SRGSSR / srgmediaplayer-apple

An advanced media player library, simple and reliable
MIT License
158 stars 33 forks source link

Avoid starting playback if sending the app to the background while the player is preparing (if no background playback possible) #73

Closed defagos closed 4 years ago

defagos commented 4 years ago

If the application is sent to the background while the player is still preparing (can be simulated with the network link conditioner), the completion handler will be called when the player is ready, at which point a call to -play from this handler might start playback in background.

While this is perfectly acceptable for audio or for video background playback if allowed, this should not occur if background behavior detaches the view (in which case we should probably pause the playback to simulate the associated effect).

I naively see two possible fixes:

defagos commented 4 years ago

~We should also add some UT for pause / stop / etc. while preparing to play.~ Done.

defagos commented 4 years ago

It's funnier than expected: The player item never reaches AVPlayerItemStatusReadyToPlay (video and audio) if the app is sent to the background while preparing to play. Once the application is resumed this status is reached immediately, and playback starts.

defagos commented 4 years ago

The issue was first reported with our Letterbox player, but I thought the culprit was Media Player. It does not seem so. I have opened a similar issue for Letterbox and closed this one.