How to mute sound in MPMoviePlayerController iPhone

How to disable and enable MPMoviePlayerController sound. I tried useApplicationAudioSession this property, even if it does not work. Can you help me?

+3
iphone
May 03 '11 at 9:05
source share
3 answers

Is it never too late to answer correctly? Looking for a way to do this, and it took me a while to find the right links.

First note that useApplicationAudioSession now (iOS 6) deprecated

Setting up a surround session will prevent audio from stopping in other applications

Install this somewhere in your code: [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryAmbient error:nil];

Here's the document https://developer.apple.com/library/ios/documentation/AVFoundation/Reference/AVAudioSession_ClassReference/index.html

Here's an explanation https://developer.apple.com/library/ios/documentation/Audio/Conceptual/AudioSessionProgrammingGuide/Introduction/Introduction.html

https://developer.apple.com/library/ios/documentation/Audio/Conceptual/AudioSessionProgrammingGuide/Introduction/Introduction.html

In my case, setting the category to AVAudioSessionCategoryAmbient did the trick!

+12
Dec 03
source share

I just want to add to this discussion here in 2016 to say that muting still works in Xcode 8. Note that I am using NSUserDefaults to track whether the user is turned on by the side switch or not:

  // Mute audio depending on side switch state if ([[NSUserDefaults standardUserDefaults] boolForKey:@"RINGER_IS_ON"]) { [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil]; // Ignore the side swicth - play audio } else { [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryAmbient error:nil]; // Respect the side switch - don't play audio } 
+1
Sep 17 '16 at 7:58
source share

Check the last line

 useApplicationAudioSession 

A Boolean value that indicates whether the video player should use an application audio session.

 @property (nonatomic) BOOL useApplicationAudioSession 

Discussion

The default value of this property is YES. Setting this property to NO forces the player to use audio sessions with the system in an immiscible playback category.

Important: in iOS 3.1 and earlier, the movie player always uses the included audio sessions. To get the same behavior in iOS 3.2 and later, you must set this value to the NO property.

When this property is YES, the movie player shares the sound of the application session. This gives you control over how movie content interacts with your audio and audio from other applications such as iPod. For important guidance on using this, see "Working with Movies and iPod Music" in the audio session of the Programming Guide.

Changing the value of this property does not affect the currently playing movie. To re-configure the effect, you must stop playback and then start it again.

 [[MPMusicPlayerController applicationMusicPlayer] setVolume:(use a value between 0.0 and 1.0)] 

If your MPMoviePlayerController uses an audio application session, this should adjust the volume. But be careful when using this. This is work around

0
May 03 '11 at 9:17
source share



All Articles