No playback from AVPlayer after app returns from a suspended state

212 Views Asked by At

I have an AVQueuePlayer which is working as expected except for after returning from a suspended state.

It's playing a HLS audio stream. The logic for my pause button is very simple

isPlaying ? player?.play() : player?.pause()

I've checked the state of the player and the currentItem, all of which say it's "playing". But the audio does not progress or playback

player.rate = 1
player.currentItem.asset.isPlayable = true
player.status == readyToPlay
player.currentItem.status == readyToPlay

I'm also setting the session with:

do {
    try session.setCategory(AVAudioSession.Category.playback, options: [])
    try session.setActive(true, options: [])
} catch {
    print("Failed to set session active")
}

AVPlayer won't resume after this

Any advice on how to troubleshoot this would be greatly appreciated. Do I need to keep track of the app entering a suspended state and reload the AVPlayerItem?

1

There are 1 best solutions below

3
matt On

Do I need to keep track of the app entering a suspended state and reload the AVPlayerItem?

It is not suspension of the app that you need to keep track of; it's interruption of the audio session. AVAudioSession provides a notification for exactly this purpose.