crossfading effect with AVPlayer - ios

I want to create crossfading effect with two AVPlayer, one player for current track and other for nextTrack. where player one is my central player(tracking remote control event and progress), on player one did finish playing event second player become central player. Thanx!

Related

In which cases avplayer should play? Like play() function, set player rate

I set player to pause and i am setting player rate after the pause. After setting player rate avplayer starting the playing without play() method, so i want to know in which other cases that avplayer should play without play() method.
I find that when we set rate or seek to specific time than it is play but i want to know is there other cases when avplayer should play.
Please check https://github.com/teamSolutionAnalysts/sa-plug-avplayer which is very easy plug and play module, lets you play video easily and you tube embedded url supported.

Two AVPlayer videos out of sync (Swift)

I have two AVPlayer() items playing videos of the same duration (10 seconds). The goal is to have them loop and stay in sync with one another. I add them as sublayers of the same UIView and then call player.play() on each one of them.
The problem though is that as code execution obviously has the slightest delay as one is called after the other one, the videos are out of sync (although only a few milliseconds, it is noticeable).
I do not have the option to create an AVMutableComposition as I have seen other posts suggest, so is there anyway to have two separate players truly stay in sync and play EXACTLY at the same time?
Thank you!
If you want to achieve the sync, you should load the videos separately with AVPlayer and observe the AVPlayerItemStatus property of each player. Only when all of the players have the status .readyToPlay you can loop through the players and set the .rate property.
Edit:
You can also synchronize them by using setRate(_:time:atHostTime:). Don't forget begin loading media data using preroll(atRate:completionHandler:) before calling setRate. Basically:
wait for readyToPlay
preroll(atRate:completionHandler:) when all players are ready
setRate(_:time:atHostTime:) when all players were prerolled

MPMovieplayer now playing issue iOS

I have one view control that consists of MP Movie Player control. This control loads video from url. It loads the video perfectly. When I move to the previous control which has TableView, the audio of the video is played in background prefectly. The control which has a TableView consists of 'Now Playing' button. On pressing of 'Now Playing' the user is moved back to MP Movie Player control. But the problem persist here is that the video is loaded again where it was instead of continuous playing.
You need to get the current position of the movie from the property currentPlaybackTime while on your TableView. Then when you move to the MP Movie Player control, you need to specify the currentPlaybackTime you had used in the TableView.

Gapless and non freeze playing of player items using AVQueuePlayer

I have some issue with avqueueplayer like app freezing for 2-3 seconds when each item ends in the queue. I am using queueplayer to play the records one after the other without gap. In order to achieve no gaps b/w player items, I need to load the assets for a player item in advance. I load assets for current playing player item and next player item so that there will be no gap at the end of 1st record. As the 1st record ends, I add 2nd player item to queueplayer to play and also load assets for 3rd player item.
In this way my playerqueue always contains a single player item but asset loading will be done for current playing item and next playing item. This will keep moving as the new records are added.
I found that a freeze of half a second is observed in new iOS devices and around 3-4 seconds in old iPod devices like iPod 4?
Can I know how we can achieve gapless and yet non freeze UI experience?
Thanks
Try lifting your requirement to only have a single player item in the queue.
An AVQueuePlayer will operate more effectively at item transitions if there is an item in its queue beyond what's currently playing.
"Loading" media can mean a few different things, and it's not clear what you're doing. Maybe you're downloading media outside of AVFoundation, building an AVAsset or building an AVPlayerItem. The work you're doing or deferring will vary depending on the kind of media (e.g an mp4 vs an HLS stream). Even if you "preload" everything (which is much more complicated for HLS media), AVFoundation still has more work to do that it won't start until the AVPlayerItem is put in a player. It has to set up a render pipeline specific to the media it needs to play back, and then start the rendering process. AVQueuePlayer can achieve gapless playback by starting some of that process before playback for that item needs to start. The queue player is also efficient about its use of resources in that it won't start loading items far down the queue until it needs to.

Multiple MPMoviePlayerController in one view

I have multiple MPMoviePlayerControllers in one view.
When a play one of them while there is already another one is playing,
the playing one is "Paused"(I'm not sure the real state it is, but more like "Stucked")
How can i know which one of the MPMoviePlayerControllers is Stucked?
Its restriction by apple, in single view controller only single movie player will get played. If one player is in play state and you are trying to play another then first player will get in pause/stop mode.

Resources