I'm new to iPhone development. Just wondering what the difference is between the MPMoviePlayerController and the MPMoviePlayerViewController. Also, more generally, what is the difference between a controller and a view controller? I know that you use a controller to construct a view (as with MPMoviePlayerController.view), so what does a ViewController create?
The MPMoviePlayerController is just a movie player, it provides a way for you to play movies on the iPhone, a MPMoviePlayerViewController is an actual view controller subclass that takes care of presentation of the MPMoviePlayerController...as documentation at apple puts it
"An MPMoviePlayerController instance, or movie player, manages the playback of a movie from a file or a network stream. Playback occurs either in full-screen mode or in a custom view that is vended by the movie player. You can incorporate the view into your own view hierarchies or use an MPMoviePlayerViewController object to manage the presentation for you."
There is no relation between a viewControler and a controller, this class just happens to be named MPMoviePlayerController because it gives you control over the movie player. Actually before (4.0 i think) there was no view controller and just the movie player, later apple decided to incorporate the movie player view controller too.
Zaius,
In the simplest terms, MPMoviePlayerViewController displays the movie/video using the MPMoviePlayerController.
hence, MPMoviePlayerController is a property in MPMoviePlayerViewController that you can access.
MPMoviePlayerViewController.moviePlayer is the property that you'd use to access MPMoviePlayerController properties.
Hope anyone hitting this thread will find this useful!
Example:
MyMoviePlayerViewController * moviePlayerVC = [[MPMoviePlayerViewController alloc]initWithContentURL:movieURL];
moviePlayerVC.moviePlayer.allowsAirPlay = YES;
Related
I have a universal app and 2 storyboards(for iPad and iPhone). In a view controller, when I tap a button, a video is starting to play. I am doing that with:
-(void)playMoviesForItems:(NSArray *)shopItems{
VideoPlayerViewController* moviePlayer = [self.storyboard instantiateViewControllerWithIdentifier:#"videoPlayerController"];
[self presentViewController:moviePlayer animated:NO completion:nil];
[moviePlayer playMoviesForItems:shopItems];
}
In iPad, everything works fine. But in iPhone, i can hear the sound of the movie, but there is no view. It is not presented like it does in iPad.
So where am I wrong? Is it the good way to present a video controller?
I think your frame for the video player is not setted properly.You have to use proper class or like present modal view controller.I am able to play the video in iphone using video player.How come it will not work for you?Is apple making junk changes i hope not so..
I am using MPMoviePlayerViewController for playing the sound and video. I am streaming the song from the url. It is working fine.But the problem is, MPMoviePlayerViewController is not showing the time progress for the song I playing. That bar is disabled. How to make the time progress bar active? I have following code to play the song.
mediaPlayerController = [[MPMoviePlayerViewController alloc] initWithContentURL:songUrl];
[self presentModalViewController:mediaPlayerController animated:YES];
[[mediaPlayerController moviePlayer] play];
If you want to show the current progress time on your own custom way, you can show it by using the currentPlaybackTime property in the MPMediaPlayback protocol gives you that info.
U use AVPlayer for playing live streaming. Refer this link.
Also refer StitchedStreamPlayer link sample code by apple.
Set controlStyle for mediaPlayerController:
[mediaPlayerController moviePlayer].controlStyle = MPMovieControlStyleFullscreen
In one View Controller ViewController1, I have tried to open a You tube video embedded in a UIWebview. It opens in the Movie Player window and then I use the "Done" button to come out of the movie player window. Again in another view controller ViewController2 in the same application, I open a MPMoviePlayerController(MPMoviePlayerController *audioplayer) to play an audio file using streaming. However, it remains in the paused state on opening the player. Even when i call the method [audioplayer play], the application automatically sets back the playback state to paused (i rechecked and it is not done through my code).
But if i reopen the application and in view controller ViewController2 i play the audio alone, then MPMoviePlayerController *audioplayer plays successfully.
Any idea what i might be doing wrong ?
This issue was found to be specific only to ios4.0.
This issue doesnt occur in ios4.1 and above.
I have a table view that has a list videos. When I click on one it uses MPMoviePlayerController to play the corresponding video. I cannot figure out how to have the player return to the list-view when the video finishes or I click on the done button.
I read the documentation and they said there was a
MPMoviePlayerPlaybackDidFinishNotification.
I figure I could have code that would go off when the notification was sent to go back to my list-view, but:
I do not understand notifications. Are they like using a delegate for a call back?
After I detected the notification, how would I tell the player to go away?
If you use the MPMoviePlayerViewController then the approach is something like:
MPMoviePlayerViewController *player = [[MPMoviePlayerViewController alloc] initWithContentUrl:url];
[myViewController presentMoviePlayerViewControllerAnimated:player];
You don't need to worry about the notification then. Once the user clicks done the movie player will go away.
I am trying to play video inside a view so I can move it around, perform layout together with other views, but I can't seem to get it work to using MPMoviePlayerController. I came across this link on how to play video in portrait mode but this is not possible because the video source is coming from the web and should be playable in different platforms not only on iPhone.
I've been successful rotating the video and scaling it but it is still contained in a UIWindow which fills the whole screen. Is there a way to create an intermediate UIWindow but not visible in the current screen, so you can play the video there and probably add subviews and return everything as a UIView where I can place it anywhere? Similar to creating a CGGraphics context draw objects there and output as an image. This would also prevent the current screen from rotating from portrait to landscape.
----- 2010/06/22 06:10+08:00 ---
IN response to Jasarien's answer (below), actually it is possible to rotate and scale a video. After the video has preloaded it creates another instance of UIWindow which then becomes the keywindow at that moment. By creating a callback selector at MPMoviePlayerContentPreloadDidFinishNotification, it is possible to apply transform modification of the current keywindow.
-(void)myMovieFinishedPreloading:(NSNotification*)aNotification {
NSArray *windows = [[UIApplication sharedApplication] windows];
UIWindow *moviePlayerWindow = nil;
if ([windows count] > 1)
{
moviePlayerWindow = [[UIApplication sharedApplication] keyWindow];
}
CGAffineTransform transform = CGAffineTransformMakeScale(0.5, 0.5);
transform = CGAffineTransformRotate(transform, -90.0f*M_PI/180.0f);
[moviePlayerWindow setTransform:transform];
}
Now my question is now that its part of UIWindow and since UIWindow is a UIView subclass, is it possible to subview this UIView? Also I can't seem to disable the autorotate behavior upon preloading of the video.
Video on the iPhone is played fullscreen at all times. The iPad with iOS 3.2 has APIs that allow a video to be treated as a normal view.
For the iPhone, without writing your own video view you're not going to be able to get the functionality you want.
Check out AVPlayer and AVPlayerLayer.