Transition avplayer to fullscreen from embedded view - ios

I am currently displaying a video embedded in a view. On tap of this video I need to present it in full screen just like how App Store does it.
Right now I am using AVPlayer to embed in the view with a AVPlayerLayer. When I detect a tap on this embedded player, I am creating a AVPlayerViewController and setting its player object with the player currently embedded, but still I can notice a delay of 3~4 seconds until the player in fullscreen starts playing. How can I make this transition smooth ?

Related

Play the video in two view controllers from where the previous video stopped

I have a table view controller that has a video view in each cell.
Each cell has a play button, slider and a full screen button.
I have implemented logic for playing , pausing and seeking the video using AVPlayerLayer.
When I click on the full screen button I am moving to another view controller where I will play the video in full screen in portrait and landscape mode
When I move to the full screen controller I want the video to play from where it was playing in the previous view controller.
And when I move back to the previous view controller the video should play from where it played in the full screen controller.
How can I achieve this? Any help will be appreciated. Thank you
I have implemented same for an audio player which has a mini player and tapping on it will open in full screen.
I have detached audio player from UI. Created singleton class of player which will update UI. So there will be only one instance of player which will update multiple UI in sync.
You can implement same logic for your player.

Make AVPlayerViewController keep playing after done button pressed

I have an instance of AVPlayerViewController playing a live broadcast content that I am adding as a subview to my viewController's view.
After switching the AVPlayerViewController to fullscreen mode and tapping Done button to exit fullscreen the player stops playing.
Is there any way to keep the player playing after done button action?
This is not possible with AVPlayerViewController. But when using fullscreen button the player keeps playing. For my case I ended up by creating a custom player controller with an AVPlayer instance.

Change the view that a video is playing on

In my app the user can play a video and leave the screen and it will continue to play in the background (just the audio). They can then return to continue to watch the video. This means that the view the video is in is destroyed and then recreated at a later point. Whenever the view is recreated and the player is set on it's AVPlayerLayer there is a noticeable lag in the video and more importantly the audio.
Does anyone know how to eliminate this lag?
The key to making this work without any lag / delay in the audio or video is to store the view with the AVPlayerLayer outside of the view. When reloading the controller, instead of creating a new view and assigning its player to the same player, simply attach the old view to the new view controller's view.
The view stays in memory as long as the video is still playing, that way a new AVPlayerLayer is not created and assigned to. It is the reassigning that causes the lag.

UINavigationView - Stop a video from playing when back pressed

I have a UINavigationView where I push on a ViewController containing a WebView with a YouTube video. When the video is run, then the back button is pressed on the UINavigationView, the sound of the video continues to play.
How do I stop the video playing in the WebView when it is no longer visible?
Make sure your web view is getting deallocated when the view controller goes away.

Supporting embedded and fullscreen view for custom movie player using AVFoundation

I am trying to create a custom movie player using AVPlayer. I want to support both embedded and fullscreen view. Though I am able to switch between fullscreen and the embedded view, the transition is not very smooth. The AVPlayerLayer resizes itself in jerks. Please suggest how can I create a very smooth user experience.
-Soumya

Resources