Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make MPMoviePlayerController ignore the mute switch

I want to play a video using MPMoviePlayerController but I want it to ignore the mute switch, similar to the behavior of Youtube's video player.

Any ideas?

like image 867
zohar Avatar asked Dec 08 '10 14:12

zohar


4 Answers

Use the AVAudioSession category AVAudioSessionCategoryPlayback and your app will ignore the mute switch like the Youtube app.

For example (inspired by Ken Pletzer in the comments):

#import <AVFoundation/AVFoundation.h>

// note: you also need to add AVfoundation.framework to your project's 
// list of linked frameworks
NSError *error = nil;
BOOL success = [[AVAudioSession sharedInstance] 
                setCategory:AVAudioSessionCategoryPlayback 
                error:&error];
if (!success) {
    // Handle error here, as appropriate
}
like image 148
Carl Veazey Avatar answered Nov 12 '22 05:11

Carl Veazey


_player.useApplicationAudioSession = NO;
like image 40
Andrey Avatar answered Nov 12 '22 04:11

Andrey


in Swift: Do this once before you play sound/video (for example at the beginning of your application)

do{
  try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback)
} catch {
  //Didn't work
}
like image 2
drpawelo Avatar answered Nov 12 '22 04:11

drpawelo


For anyone in the future, I know this has been answered already, but I had an issue with playing a video in my app which caused apps like spotify, youtube etc. to stop playing it's audio, so I ending up using this:

NSError *silentSwitcherror = nil;
BOOL silentSwitchSuccess = [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback withOptions:AVAudioSessionCategoryOptionMixWithOthers error:&silentSwitcherror];
if (silentSwitchSuccess)
{
//put whatever video code you are trying to play
}
else
{
//put how to handle failed instances.
}
like image 2
C-H-E-F Avatar answered Nov 12 '22 06:11

C-H-E-F