Sezhian
Sezhian

Reputation: 333

How to turn off audio in MPMoviePlayerController iPhone

How to turn off & turn on audio of MPMoviePlayerController. I tried useApplicationAudioSession this property even though it is not working. Can you please help me?

Upvotes: 4

Views: 8997

Answers (3)

user1531352
user1531352

Reputation:

I just want to add to this discussion here in 2016 to say that muting audio this way still works in Xcode 8. Note that I use NSUserDefaults to keep track of whether the user has switched on 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
    }

Upvotes: 1

pepouze
pepouze

Reputation: 171

Never too late to answer right? Was looking for a way to do it as well and it took me a while to find the right links.

First please note useApplicationAudioSession is now (iOS 6) deprecated

Setting the ambient audio session will prevent stopping audo in other apps

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

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

Here's the 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!

Upvotes: 12

visakh7
visakh7

Reputation: 26390

Check the last line

useApplicationAudioSession

A Boolean value that indicates whether the movie player should use the application’s audio session.

@property (nonatomic) BOOL useApplicationAudioSession

Discussion

The default value of this property is YES. Setting this property to NO causes the movie player to use a system-supplied audio session with a nonmixable playback category.

Important: In iOS 3.1 and earlier, a movie player always uses a system-supplied audio session. To obtain that same behavior in iOS 3.2 and newer, you must set this property’s value to NO.

When this property is YES, the movie player shares the application’s audio session. This give you control over how the movie player content interacts with your audio and with audio from other applications, such as the iPod. For important guidance on using this feature, see “Working with Movies and iPod Music” in Audio Session Programming Guide.

Changing the value of this property does not affect the currently playing movie. For the new setting to take 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 the application audio session, this should adjust the volume. But be careful in using this.. It is a work around

Upvotes: 0

Related Questions