SRGSSR / srgmediaplayer-apple

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

Sharing Streaming between Players #41

Closed tooolbox closed 1 year ago

tooolbox commented 6 years ago

Hey guys, impressive library!

Issue overview

I would like to be able to share a stream between multiple players, i.e., have a "preview" going in an inline player, and then seamlessly transfer to a main player upon a certain condition.

Check the correct option below

Description of the problem

As above. With the stock AVPlayerViewController, since it directly uses AVPlayer and you are managing the lifecycle of it, you can start an AVPlayer going, and pass it around to one more AVPlayerViewControllers, or create multiple AVPlayerLayers that all mirror the same AVPlayer. By this mechanism you have the power to have one stream playing in multiple windows or parts of your app that are totally separated from each other, in different View Controller hierarchies, etc.

Since the AVPlayer in this library has a managed lifecycle, how would I go about sharing a given stream between multiple screens/player-views?

defagos commented 6 years ago

This is entirely possible. SRGMediaPlayerController view can namely be moved to another parent view hierarchy or resized. You can therefore start playback in a tiny view, then move it to a larger player view, e.g. during a custom view controller transition. For this to work, you of course need to share the media player controller instance between the two view controllers (e.g. by providing the controller as initialization parameter of the second view controller).

An implementation example showing how media player views can be reattached on the fly is provided in our multi-stream demo sample. This demo presents simultaneous playback of three medias using three controller instances (and therefore three associated views). There is one main non-muted instance, playing in a large view, and two other instances, playing in thumbnail views. When tapping one of the thumbnails, the associated player view is moved between thumbnail and main container views, without playback interruption.

We don't provide any demo for view controller transitions at the moment, though, but this is entirely possible as well.

What we don't support is having several views mirroring the same video (AFAIK, and according to my investigations, you can have at most one AVPlayerLayer displaying the video played by an AVPlayer instance, other layers will be just blank).

Hope this answers your question.

Best regards.

tooolbox commented 6 years ago

Thanks defagos, so basically I would need to move the controller, and the view itself, between two View Controllers. Hm. That is what I thought, but I was hoping for a better way.

Per Apple's docs, you can have multiple AVPlayerLayers for one AVPlayer. I'm currently doing that in one of my apps.

Discussion You can create arbitrary numbers of player layers with the same AVPlayer object, but you should limit the number of layers you create to avoid impacting playback performance.

defagos commented 6 years ago

Thanks for the input, I created a dedicated investigation task. Though you don't need the ability to have several views display the same content to implement your transition, I still want to have a look at this possibility again in the future.

defagos commented 5 years ago

I could have several layers display the same content. Not sure if we will do something with it, but in the meantime I'll at least reopen this issue.

defagos commented 1 year ago

This feature is indeed possible and was implemented in SRG Media Player successor, found in the Player package of our new Pillarbox player platform.

This feature would sadly be difficult to implement in SRG Media Player because of its architecture, though. Closed.