calling MPMoviePlayerController from another class - ios

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.

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.

YTPlayerView not working properly

I have embedded YouTube in my application using YTPlayerView helper library for iOS the main issue I am facing right now is that I have embedded the multiple instances of YTPlayerView within scrollview and its loosing its not calling the changestate playback properly. The problem occurs when two videos are loaded concurrently.
you can not use multiple instance of ytplayer in same view as it described in this link
see here
The library does not support concurrent video playback in multiple
YTPlayerView instances. If your application has multiple YTPlayerView
instances, a recommended best practice is to pause or stop playback
in any existing instances before starting playback in a different
instance. In the example application that ships with the project, the
ViewControllers make use of NSNotificationCenter to dispatch
notifications that playback is about to begin. Other ViewControllers
are notified and will pause playback in their YTPlayerView instances.

How to control background music

I am developing an app with a background music and the music starts when the first view (INTROViewController) appears (it is implemented in viewDidLoad). I have created a settings page (OPTIONSViewController) where I have implemented a switch to turn the music on and off. In OPTIONSViewController I have created an instance of INTROViewController where all the audio files and the commands to play and stop the music are defined. I don't get any errors but it seems the instance is not able to control the music at all, which continues playing. What am i doing wrong? Cheers
I think u can have just one AVPlayer on your AppDelegate.
Declare it like a property, and then u can get this player from all your application
with something like this:
yourAppDelegate* appDele= (yourAppDelegate*)[[UIApplication sharedApplication]delegate];
AVPlayer * tempPlayer = [appDele yourPlayer];
This should fix your problem :D

Using multiple MPMoviePlayerController instances in a UITabBarController based iOS app

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?

How do I display video on external monitor while keeping controls on iPad?

My iPad app has the option to play videos. I use the MPMoviePlayerViewController class to play my videos.
My question is: if I want to play the videos on an attached external monitor, how do I keep the playback controls on the iPad like YouTube does? If I add the view of the MPMoviePlayerViewController 's player to the external screen's hierarchy I can play the video fine, but I now have no control over it. Is there a way to move or duplicate the view where the controls lie and place it on a view which resides on the iPad?
I'm not aware of an officially supported way of pulling out the original UI in this way. The MPMoviePlayerViewController only exposes the MPMoviePlayerController object it uses via its moviePlayer property. The MPMoviePlayerController in turn only exposes view and backgroundView, which aren't helpful for such a purpose. You could in theory inspect the subviews of the movie player's main view, find the playback controls and try to move them to the other screen. I have a feeling this will not end well though, as they're anything but static. You also never know what will happen in later iOS versions, or if they'll let your hack on the app store. It's probably less trouble to just re-do the UI yourself.
Actually controlling the video playback programmatically is straightforward - the view controller's moviePlayer implements the MPMediaPlayback protocol.

Resources