Using multiple MPMoviePlayerController instances in a UITabBarController based iOS app - ios

In my iPad app, the user can open one MPMoviePlayerController in each tab (total of 5).
In each viewcontroller containing a movieplayer instance, I play the movie in viewDidAppear: method, and I pause it in viewWillDisappear: method. I also add/remove the viewcontroller as an observer for notifications so that only the viewcontroller currently visible is receiving the notifications. The movieplayer is setup in the init method, and there is nothing really special about it.
Note: Although you can create multiple MPMoviePlayerController objects and present their views in your interface, only one movie player at a time can play its movie.
Besides the note above, I cannot find anything about this in the docs, but I´m guessing that the movieplayer is shared between viewcontrollers somehow, becasuse when I force one movieplayer in each tab it works sometimes, and sometimes the movieplayer is finished when I return to the previous tab.
Is it a fact that MPMoviePlayerController are meant only handle one video at a time, no matter if the instances are in different classes/tabs?

Related

tvOS issue with Siri search deeplinking integration

I have an issue where when user is playing a video , while video is being player, he uses siri to search for a different movie, which will load its corresponding movie details page and then select to play that movie, which deeplinks to your app which is playing a movie, when i play a new selected movie and dismiss avplayer and avplayercontroller, audio from previous video still continues to play. somehow avplayer is not cleared although i clear all subviews from window and initialize its super view controller class again. I am cluless what can i do erase older instance of avplayer. Let me know if anyone has any suggestions or faced similar issue.
A few suggestions:
Are you subclassing AVPlayerViewController? If so, that's a bad idea. The API docs specifically say not to do that.
Add a deinit function. If it's not being called when the old AVPlayer is dismissed, you know you have a retention problem. This is often caused by registering for notifications or boundary time observers.
If you view controller has a reference to the AVPlayer object, you might try overriding the viewDidDisappear function to call player.pause() and then setting the player reference first to a new instance of AVPlayer() then to nil. Not sure why this helps, but sometimes it does.
Definitely implement #2 above. If deinit is not getting called, you most certainly have an issue.

calling MPMoviePlayerController from another class

I would like to use MPMoviePlayerController as embedded. The real issue is i am making a small library which MPMoviePlayerController handles to play video and if API is pushing some preroll advertisements i am stopping video and starting to show ad video immediately.
From now, i was able to do it with fullscreen but, company needs embedded version of that player which going to be play in UIView or an tableviewcell.
Shortly :
MPMovieController is created another class as moviePlayer
ViewController is the basic UI Class that developers going to call moviePlayer class and embed video into ViewController's UIView
Best Regards.
Onder.
I 've solved async task from another class with moving in appDelegate. So classes which has async task can be process and callback anytime and when finish i am posting notification.

AVQueuePlayer stops playing when I navigate to previous view

I have used AVQueuePlayer several times and the default behaviour is to continue playing when you change view, but in my case when I navigate to the previous view where I came from by segue, the player stops. I put a breakpoint after dealloc to see if the AVQueuePlayer is released and from what I can see it's not deallocated (I have a strong reference to it using property). Please help!!!
I am streaming audio using several links from a server, not playing local files. I created the url, used the url to make AVPlayerItems, and added the player items into array, I used this array to initiate the AVQueuePlayer. I used GCD to make sure my array is completely ready before I play the AVQueuePlayer.
As soon I click on back button it stops. I am pulling out my hair
Create a singleton class that provides an interface to the AVQueuePlayer. That way you will be sure that it's alive even when you pop your view controllers.

Global Audio Player for tabbed App

after days of research I came to the conclusion that there is no other way than to ask here directly.
I have an tabbed application with several UITableViewControllers inside. When I click on a cell in one of these TableViewControllers there should be played some audio streams. This is working so far using MPMoviePlayerViewController. But when I click on "Done" in the player, the audio stops to play.
What I need is to be able to start the audio track, and when I click "done" it should not stop. Also, there should be a way to get back to the player.
What I was thinking is to make something like a "global view" with an integrated player and all other views in the app should use this global view to play the selected audio.
So, I created an UIView which has a method playAudio that starts playing in a MPMoviePlayerViewController. But what is the way to go to this view from another. Right now I am just calling this method directly and before that I added
[self.navigationController pushViewController:mediaPlayer animated:YES];
but I think I am on the wrong way here. What I want to achieve is to play audio in a player, that stays in background when clicking on "Done" in the player. And this player should be reached from every view (e.g. through a UIButton in each tab bar View) - just like most radio applications and music apps do.
Would appreciate any help.
For this purpose, you should not use MPMoviePlayerViewController. You can create your own audio player with view and controls, or use third party libraries (search on Google there are plenty of them). Good Luck!
You should not use MPMoviePlayerViewController to play audio because it's designed to play a movie. I recommend using AVPlayer to play audio (if you only care about local audio and you're not streaming from the Internet, AVAudioPlayer is OK too.)
When you play your audio with AVPlayer, it will continue to play even when you app goes into the background.
The view hierarchy of your app should look something like this:
Root View Controller
Tab Bar controller
Your view controllers go here
A "Now Playing" view controller
A "now playing" view controller will be a view controller that you can put audio controls and display what is playing to your user. You can make your now playing view controller a property in the app delegate or in your root view controller so that you can access it easily. For instance:
id<UIApplicationDelegate> appDelegate = [[UIApplication sharedApplication] delegate];
[self.navigationController presentViewController:appDelegate.nowPlayingViewController animated:YES completion:nil];
You can add this code to a button for any of your view controllers that needs to display the Now Playing screen.

Tell video loaded in MPMoviePlayerViewController to stop playing

I've got a navigation view with a table view in it, listing some videos. When a row is selected, it loads MPMoviePlayerViewController and inits it with a video from file URL. When I go back to the table view, the movie is still playing. I tried getting the underlying MPMoviePlayerController and giving it a "pause" message in the viewDidDisappear method, but this doesn't seem to ever get called (NSLog statement in method never appears). So I'm sure there's a simple way to tell MPMoviePlayerController via MPMoviePlayerViewController to stop playing it's movie programmatically, right?
Simply needed to subclass MPMoviePlayerViewController, load the subclass from the table/navigation on selection, then add this to that subclass:
-(void)viewWillDisappear:(BOOL)animated {
[self.moviePlayer stop];
}
You need to register for some notifications. See the 'Notifications' section of the MPMoviePlayerController class reference:
http://developer.apple.com/library/ios/#documentation/MediaPlayer/Reference/MPMoviePlayerController_Class/MPMoviePlayerController/MPMoviePlayerController.html
In particular, register to receive MPMoviePlayerDidExitFullscreenNotification and MPMoviePlayerPlaybackDidFinishNotification and in your method that is called when these notifications are sent, stop the movie from playing by sending the 'stop' message.
But what about when you want to stop downloading the video before it is finished playing. For example, when you go to a different screen.
For me, i try to stop the video when the videoWillDisappear method gets called. Yet, the video still downloads even when the current video is gone!

Resources