Multiple MPMoviePlayerController in one view - ios

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.

Related

MPMediaItem and AVPlayerItem playback sequence in background

I'm having an issue with playing sequences of different kinds of items in a background.
In an app I'm working on we've introduced playlists which contain both content provided by the app and Apple Music content.
For that use AVPlayer and MPMusicPlayerController respectively. We observe one player or the other (depending what content is now playing) and if the other kind of content comes next, we release the old player (if we can - MPMusicPlayerController is a singleton, so best we can do is stop it) and load item to another player.
The problem starts when the app leaves foreground. Once MPMusicPlayerController takes over it doesn't want to give up control, so if any AVPlayer content comes after MPMusicPlayerController content, the music stops.
One workaround that I've tried is playing with .mixWithOthers options when I set the category on AVAudioSession, however this creates new category of problems - I'm loosing lockscreen controls, therefore I'm also loosing airplay. One dirty trick that I've tried was setting .mixWithOthers 3 seconds before MPMediaItem ends, and then disabling it back once AVPlayer starts. Beside the fact that there're probably many different things that can go wrong here, MPMediaPlayerController still doesn't want to give me back the control over lockscreen controls.
Is there any way this could ever work on iOS 13?

Multiple movie files MPMoviePlayerController

I have multiple moviefiles. That i would like to make a playlist of. How can i assign the next and previous buttons to go to the next movie.
I've tried to find a solution for this for a long time, but i cant seem to find a answer for this?
And i'm not talking about dismissing the current MPMoviePlayerController and opening a new one with the new video.
You can use contentURL property of MPMoviePlayerController for playing new video.
If you set this property while a movie is playing, that movie pauses and the new movie begins loading. The new movie starts playing at the beginning.

Multiple AVPlayers on Separate UIViewControllers

I have multiple AVPlayers, each on separate UIViewControllers playing different songs.
I need to pause one AVPlayer whenever I play another one (otherwise the audio overlaps).
I would like to let the user traverse through the app while the music plays in the background, so pausing the AVPlayer on viewDidDisappear:(BOOL)animated, would not work.
What is the best way to access the controls of each separate AVPlayer?
In my opinion a singleton with only 1 AVPlayer solves this issue well. This way you guarantee that to play another song you have to stop the previous. Then, in that AVPLayerSingleton you have a private property called avPlayer. You can define two methods:
- (void)createPlayerWithSong:(NSString *)currentSong;
- (void)destroyPlayer
Then, in your createPlayerWithSong you can check if avPlayer is already created and destroy it and create a new one for each new song.
Couple of ways you could do it:
Create a shared singleton object that have weak properties that reference each AVPlayer. That way you can control it from anywhere.
OR
Use NSNotificationCenter to send notifications when you want to control an AVPlayer on a different view controller. This might get cumbersome if you have a lot of AVPlayers you want to control.

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.

AVtouch problem

In my app, I select one song from tableView and played in default player,
and then when i back to playlist (i.e tableview) and select another song
then BOTH songs played simultaneously.
How I solve this problem ? I want to play when another song select then that selected song must played and previous one should be stopped.
Please HELP.
Thanks in advance.
Hurray Problem solved....
Problem: Multiple songs overlapping in player.
Reason : Multiple instance creation of AVAudioPlayer.
Solution: Create only one instance at launch, and when play called
then [audioplayer stop] then play (using flags avoid multiple creation).
Thanx to all.

Resources