Getting MPMoviePlayerController to Work with iOS4, 3.2 (iPad) and Earlier Versions of iPhone SDK
Here we are disusing about how to create MPMovieplayerController and how to know MPMovieplayerController is ready to play the movie
!.crating player
- (void) createPlayer { mp = [[MPMoviePlayerController alloc] initWithContentURL:movieURL]; // Set movie player layout [mp setControlStyle:MPMovieControlStyleFullscreen]; [mp setFullscreen:YES]; // May help to reduce latency [mp prepareToPlay]; // Register that the load state changed (movie is ready) [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerLoadStateChanged:) name:MPMoviePlayerLoadStateDidChangeNotification object:nil]; // Register to receive a notification when the movie has //finished playing. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil]; }
- (void) moviePlayerLoadStateChanged:(NSNotification*)notification { // Unless state is unknown, start playback if ([mp loadState] != MPMovieLoadStateUnknown) { // Remove observer [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerLoadStateDidChangeNotification object:nil]; // When tapping movie, status bar will appear, it shows up // in portrait mode by default. Set orientation to landscape [[UIApplication sharedApplication] setStatusBarOrientation: UIInterfaceOrientationLandscapeRight animated:NO]; // Rotate the view for landscape playback [[self view] setBounds:CGRectMake(0, 0, 480, 320)]; [[self view] setCenter:CGPointMake(160, 240)]; [[self view] setTransform:CGAffineTransformMakeRotation(M_PI / 2)]; // Set frame of movie player [[mp view] setFrame:CGRectMake(0, 0, 480, 320)]; // Add movie player as subview [[self view] addSubview:[mp view]]; // Play the movie [mp play]; } }2.Knowing the MPMovieplayerController is ready to play the movie
in ios4 and above the
MPMoviePlayerLoadStateDidChangeNotification is very important notification which is called when movie is loaded for memory to play.If movie content is corrupted,invalid movie type this notification is not fired.and MPMoviePlayerPlaybackDidFinishNotification call imedetly and no movie is played.
you can get user info dictionary of MPMoviePlayerPlaybackDidFinishNotification to know reason of movieplaybackfinish.
(void) moviePlayBackDidFinish:(NSNotification*)notification { NSIntgerif user infomovieFinishReason= [[[notification userInfo]objectForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey] intValue]; }
MPMovieFinishReasonPlaybackEnded = 0,//played movie sucessfuly. MPMovieFinishReasonPlaybackError = 1, //error in playing movie MPMovieFinishReasonUserExited = 2; //user quitting the application.
Please comment below with any comments or questions you may have… and also if you like babes or dudes. :]
hello.... one need, i want to add layer on mpmovieplayer full screen mode view or subview.... how i can add... please help me to do..... on the layer i have to add text for watermark purpose
ReplyDeletehello.... one need, i want to add layer on mpmovieplayer full screen mode view or subview.... how i can add... please help me to do..... on the layer i have to add text for watermark purpose
ReplyDelete