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

Add PiP support to SystemVideoView #610

Closed
19 tasks done
defagos opened this issue Oct 23, 2023 · 5 comments · Fixed by #628
Closed
19 tasks done

Add PiP support to SystemVideoView #610

defagos opened this issue Oct 23, 2023 · 5 comments · Fixed by #628
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@defagos
Copy link
Member

defagos commented Oct 23, 2023

As a developer integrating Pillarbox and the standard system UI I want to be able to add PiP support to my application.

Acceptance criteria

  • PiP can be enabled in the demo (examples with the system UI and demo-wide opt-in).
  • Expected PiP behaviors work well:
    • Enable when transitioning to the background or switching to another app (without interruption).
    • Enable with dedicated button.
  • Player UI controls are correct.

Tasks

  • Wrap AVPlayerViewController in VideoView view controller representable.
  • Provide lifecycle customization API.
  • Implement correct dismissal and restoration, in particular:
    • Automatic restoration when returning to the same content.
    • Correct reset when dismissing without PiP or using the PiP overlay close button.
  • Ensure it works well everywhere (most notably custom player and playlist).
  • Restore full screen if selecting the content already being played in PiP.
  • Ensure that the behavior is correct when PiP is started from a maximized state (double-ended arrow at the top left pressed).
  • Provide PiP as opt-in for the view if this makes sense (i.e. if additional integration work is required for the opt-in).
  • Ensure that controls at the top left are correct (no need for custom close button anymore).
  • Ensure that resources do not leak. In particular when moving from PiP enabled for player A by playing content with another player B (reference counting strategy to manage global models?).
  • Improve example names (VideoPlayer examples vs. other examples which use our own system view). Maybe we could have simple AVPlayerViewController vanilla wrapping and VideoPlayer sections for comparison.
  • Check whether we can use the same view model for the system and the custom players.
  • Check if FB11934227 is still an issue with the new updated implementation and remove the associated comment if not the case anymore.
  • Disable PiP button if a parent view is not enabled for PiP.
  • Check behavior with preventsDisplaySleepDuringVideoPlayback. Create story if needed.
  • Improve PiP lifecycle protocol:
    • Remove Boolean from completion (always pass true internally).
    • Think about an async variant instead if feasible / meaningful.
@defagos defagos converted this from a draft issue Oct 23, 2023
@defagos defagos added the enhancement New feature or request label Oct 23, 2023
@defagos defagos added this to the PiP milestone Oct 23, 2023
@defagos defagos changed the title Add PiP support to SystemVideoView Add PiP support to SystemVideoView Oct 23, 2023
@defagos defagos moved this from ✏️ Draft to 📋 Backlog in Pillarbox Oct 23, 2023
@defagos defagos moved this from 📋 Backlog to 🚧 In Progress in Pillarbox Oct 24, 2023
@defagos
Copy link
Member Author

defagos commented Oct 24, 2023

@waliid discovered that the usual AVPlayerViewController full screen button is still present and interactive on VideoPlayer, though it can be seen (width of AVMobileChromelessDisplayModeControlsView is zero). This is a bug we have to report to Apple. We can likely assume that the button should be visible since VideoPlayer should not differ much from wrapping AVPlayerViewController in a UIViewControllerRepresentable.

For this reason our SystemVideoView will be updated as follows:

  • Replace VideoPlayer with a UIViewControllerRepresentable wrapping an AVPlayerViewController. This means the view will always display a button at the top left, either a full screen or a close button.
  • Remove support for content overlays (not used yet anyway).
  • Document our VideoPlayer view behavior as intentionally matching the one of AVPlayerViewController, that means:
    • Inline integration leads to a full screen button being displayed.
    • Full screen integration leads to a close button being displayed.

@defagos
Copy link
Member Author

defagos commented Oct 26, 2023

The approach of sharing AVPlayerViewController between view instances has a great advantage (same for AVPlayerLayer sharing we will do for the custom PiP integration with AVPictureInPictureController instead of AVPlayerViewController. No matter the views between which playback is moved through PiP, restoration will never kill the PiP overlay abruptly. The player layer will always move between maximized display and PiP overlay. This is a great improvement over what we had with Letterbox.

@defagos defagos moved this from 🚧 In Progress to 📋 Backlog in Pillarbox Nov 3, 2023
@defagos defagos moved this from 📋 Backlog to 🚧 In Progress in Pillarbox Nov 7, 2023
@defagos
Copy link
Member Author

defagos commented Nov 8, 2023

The system video view has two modes:

  • Full screen display: In this case the player can only be closed. When used in apps (e.g. tv+) the player is dismissed when PiP is entered.
  • Inline display: In this case the player has a maximization button. Starting PiP must not dismiss the player, PiP is only meant to detach the layer, letting the user navigate away afterwards (see e.g. Apple Developer app).

We should document these use cases. We should also document that the use case start inline, maximize, move to PiP with dismissal is not supported. Dismissal is namely only intended for full screen use.

Our demos should also be updated to have both these use cases properly implemented.

@defagos
Copy link
Member Author

defagos commented Nov 10, 2023

FB11934227 is still an issue with the new implementation.

@defagos
Copy link
Member Author

defagos commented Nov 10, 2023

The screen is prevented from sleeping while playing in PiP. No further preventsDisplaySleepDuringVideoPlayback investigation needed yet.

@waliid waliid linked a pull request Nov 10, 2023 that will close this issue
5 tasks
@github-project-automation github-project-automation bot moved this from 🚧 In Progress to ✅ Done in Pillarbox Nov 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Archived in project
2 participants