Search code examples
iosvideoavplayerinterruption

AVPlayer video becomes blank when another audio is active


I'm using AVPlayer to play video. And follow these steps

  • Open Music app, play a song, and pause it
  • Go to my app and play a video
  • With the headphone plugged in, press the middle button to resume Music app playback

Then the Music app plays, but my video goes blank. From reading Responding to Interruptions

An audio interruption is the deactivation of your app’s audio session—which immediately stops or pauses your audio, depending on which technology you are using

I understand that my video should pause, but why does it also blank the video?

Only after I press the middle button on the headphone again to pause the Music, then my video goes normal again, but remains in paused state

Is this normal behaviour, how to prevent this?


Solution

  • After trying to disable Music app MPNowPlayingInfoCenter, I found

    Just call these before playback

    [[AVAudioSession sharedInstance] setActive:YES error:nil];
    [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
    [[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
    

    This will disable Music app, and toggling middle button on the headphone has no effect on us