Adding custom controls to a full screen movie - iphone

Is it possible to add custom controls to a movie playing in full-screen mode ( with MPMoviePlayerController )? I've seen this in a few streaming apps, and I'm curious how it is done.

You can turn off the standard controls of the player and create custom buttons that call play, pause etc on the player. If you set fullscreen to NO, you can make the players frame whatever you want (fullscreen) and layer your custom controls on top.
Something like:
MPMoviePlayerController *mp = [[MPMoviePlayerController alloc] init];
[mp setControlStyle:MPMovieControlStyleNone];
[mp setFullscreen:NO];
[[mp view] setFrame:CGRectMake(myX, myY, myWidth, myHeight)];
[myCustomController setMoviePlayer:mp]; // so controller can send control messages to mp
[myView addSubview:mp.view];
[myView addSubview:myCustomController.view];
or whatever...

Related

Playing Multiple Videos on iPAD

I am facing some problem in playing multiple videos on iPAD. I am trying to play multiple thumbnail videos on the same view. You can say its much like the CCTV camera.Well, i have no clue. Please help me. Thanks in advance...
MPMoviePlayerController will allow multiple instances, but only one of them can be playing their movie at any given time.
It mentions it here: http://developer.apple.com/library/ios/#documentation/mediaplayer/reference/MPMoviePlayerController_Class/MPMoviePlayerController/MPMoviePlayerController.html
From the article:
Note: Although you may create multiple MPMoviePlayerController objects and present their views in your interface, only one movie player at a time may play its movie.
You can't use the MKMediaFramework to play multiple videos. You can however do this with the lower level AVFoundation Framework. It's not as hard as you might think and I've made a tutorial that goes over it here: http://www.sdkboy.com/?p=66
Essentially what you need to do is extend UIView so it contains an AVPlayerLayer to which the output of an AVPlayer object is directed, then you can create multiple instances of this UIView that you feed video using AVPlayer instances.
This is actually pretty simple to do on the iPad.
You basically need multiple MPMoviePlayerController objects.
Each MPMoviePlayerController object has a view property, you just need to set the frames of the views on the different MPMoviePlayerController objects to match what you want it to look like.
Here is a simple example using two MPMoviePlayerController objects ans 2 different frames:
MPMoviePlayerController *player =
[[MPMoviePlayerController alloc] initWithContentURL: myURL];
[[player view] setFrame: yourFrame1];
[myView addSubview: [player view]];
// ...
[player play];
MPMoviePlayerController *player2 =
[[MPMoviePlayerController alloc] initWithContentURL: myURL2];
[[player2 view] setFrame: yourFrame2];
[myView addSubview: [player2 view]];
// ...
[player2 play];
May be When Creating a WebView and using a HTML5 Video instance you can run multiple videos at the same time

How to show "Loading Movie..." message with MPMoviePlayerController

I'm working with the MPMoviePlayerController for the iOS platform and am not sure why the "Done" and "Loading Movie..." controls are not displaying automatically when loading a new video.
My original implementation of this was to use the UIWebView control to stream the videos, and when the videos are accessed, the "Done" and "Loading Movie..." controls are displayed until the video is loaded and ready to play. I would like to reproduce the same user experience with the MPMoviePlayerController.
Should I get the "Done" and "Loading Movie..." control overlays for free? If not, what do I have to set to get them to show up while the video is loading?
NSURL *videoUrl = [NSURL URLWithString:urlString];
self.moviePlayer = [[[MPMoviePlayerController alloc] init] autorelease];
self.moviePlayer.movieControlMode = MPMovieControlModeDefault;
[self.moviePlayer setContentURL:videoUrl];
[self.moviePlayer prepareToPlay];
[self.view addSubview:self.moviePlayer.view];
[[self.moviePlayer view] setFrame: [self.view bounds]];
[self.moviePlayer setFullscreen:YES animated:YES];
This is answer to your follow-up question, but anyways... You can speed-up things a little bit with this:
prepareToPlay
Prepares the current item for playback. (required)
- (void)prepareToPlay
This method is called automatically when you call the play method. Calling it before you call play gives the receiver a chance to prepare items sooner and may result in decreased latency when starting playback. However, calling this method may also interrupt any active audio sessions.
Available in iOS 3.2 and later.
Declared In MPMediaPlayback.h

Play videos fullscreen in landscape (iPhone)

I have an app that is built as a hierarchy of viewControllers.
On of the view Controllers is for a 'video section' of the app.
The app is designed to be portrait only, however, I want to force the videos to play fullscreen in landscape (just like the iPod app on the iPhone).
After searching around, I see that many people have this problem.
I finally have been able to rotate it, but it doesn't work in full screen, that defaults to portrait.
And since it doesn't work in full screen, you see elements in the parent views over the video.
Is there an easy way to rotate this video in full screen, or do I have to broadcast a message to the parent views to hide elements when the video is playing?
here is the code:
NSURL *url = [NSURL URLWithString:[recipeData objectForKey:#"videoPath"]];
MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
// Register to receive a notification when the movie has finished playing.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];
moviePlayer.controlStyle = MPMovieControlStyleFullscreen;
moviePlayer.scalingMode = MPMovieScalingModeAspectFill;
moviePlayer.shouldAutoplay = YES;
moviePlayer.view.frame = [[UIScreen mainScreen] applicationFrame];
moviePlayer.view.transform = CGAffineTransformMakeRotation(1.57079633);
moviePlayer.view.bounds = CGRectMake(0.0, 0.0, 480, 320);
[self.view addSubview:moviePlayer.view];
//commenting out the line below will rotate the video, leaving it uncommented forces it to play fullscreen in portrait
[moviePlayer setFullscreen:YES animated:NO];
I put the method to create the video in the appDelegate and target it whenever the video is launched. This did the trick, keeping it above everything else.
Have you tried using MPMoviePlayerViewController instead? it presents a full screen almost modal view Controller to handle the video playing. I use it in >=3.2 version and use a hacked up version of MPMoviePlayerController for <3.2
For full screen playback you should use MPMoviePlayerViewController and then to make it launch and play in landscape format use the "shouldAutorotateToInterfaceOrientation" method on the MPMoviePlayerViewController class.
Looks like this:
[yourInstanceOfMPMoviePlayerViewController shouldAutorotateToInterfaceOrientation: UIInterfaceOrientationLandscapeRight];

MPMoviePlayerController questions, best practices

I have any number of thumbnail images that, when tapped, will play a different video (fullscreen). I have never been clear on whether I should keep one MPMoviePlayerController object in my view controller and have it play whichever url according to the thumbnail that was tapped, or create a new MPMoviePlayerController each time. What is the best practice?
I am also having problems where tapping on different thumbs crashes the app, I believe because the MPMoviePlayerController tries to stream a video while it is already trying to stream. There seems to be no way to cancel a MPMoviePlayerController and clear out what it was doing, then start loading a new video.
Here's how I create it:
MPMoviePlayerController* moviePlayer = [[MPMoviePlayerController alloc] init];
self.player = moviePlayer;
[moviePlayer release];
Then to play a video I do this:
//would like to do something like this first - [self.player clear];
self.player.contentURL = someURL;
[self.view addSubview:player.view];
[self.player prepareToPlay];
[self.player play];
Any advice is welcome... thanks.
When you are changing the video in an MPMovieplayerController,then you can remove the mpmoviecontrollerplayer view from super view using removeFromSuperView and again add it's subview to the super view initializing it with new URL.
No need to create new object every time.

MPMoviePlayerController for iPhone App on iPad

For some reason, the expand button the arrow points to in the screenshot below causes the view controller that initiated video playback to animate back over top of the video, but without stopping video playback which means you can still hear the audio even though the video is no longer visible. I've tried other movie control styles, but there are other problems with those (for example, no controls causes the player to play the entire video before dismissing, i.e. no 'Done' button).
Here is the code that initiates the video playback:
player = [[MPMoviePlayerViewController alloc] initWithContentURL:movieURL];
[player setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
[[self navigationController] presentModalViewController:player animated:YES];
[[player moviePlayer] play];
Any ideas/suggestions as to how I can either disable that button or receive its notification so I can respond accordingly?
Thanks.
I can't find a solution to this, but I did find a workaround. I simply call [player stop]; in my -viewDidLoad of the calling view controller. The outcome won't be what the user expects when they press that button, but it's better than allowing the video to continue to play when they press it.