Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
defagos opened this issue Nov 15, 2019 · 3 comments

Comments

@defagos
Copy link
Member

defagos commented Nov 15, 2019

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:

  • We can avoid calling the completion handler in this case. I don't like this approach, as this would also impact playback being prepared into the paused state (i.e. without call to -play from the handler).
  • Call -pause on AVPlayer after the completion handler has been called, if SRGMediaPlayerViewBackgroundBehaviorAttached and we know that the loaded content is a video. This seems better to me. We probably have to also check AirPlay status or other settings which might affect this behavior.
@defagos
Copy link
Member Author

defagos commented Nov 15, 2019

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

@defagos
Copy link
Member Author

defagos commented Nov 15, 2019

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
Copy link
Member Author

defagos commented Nov 15, 2019

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.

@defagos defagos closed this as completed Nov 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant