How to make MPMoviePlayerController ignore the mute switch

后端 未结 5 1878
無奈伤痛
無奈伤痛 2021-02-07 02:21

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?

5条回答
  •  粉色の甜心
    2021-02-07 02:29

    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 
    
    // 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
    }
    

提交回复
热议问题