Continue playing audio from a video asset when the video moves into the background.
A common feature of many media playback apps is to continue playing audio when the app is sent to the background. This may be the result of a user switching apps or locking the device. To enable your app to play background audio, you begin by configuring your app’s capabilities and audio session, as described in
AVAudio and Enabling Background Audio.
Connect or Disconnect the Video Player
If you’re playing audio-only assets, such as MP3 or M4A files, your setup is complete and your app can play background audio. If you need to play the audio portion of a video asset, an additional step is required. If the player’s current item is displaying video on the device, playback of the
AVPlayer instance is automatically paused when the app is sent to the background. If you want to continue playing audio, you disconnect the
AVPlayer instance from the presentation when entering the background and reconnect it when returning to the foreground.