MPMoviePlayerController does not delete view when clicked

I create an MPMoviePlayerController object and transmit the video in full screen.

I am using a UIViewController to display a movie view.

- (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; //http://www.youtube.com/watch?feature=player_detailpage&v=ebeQaznNcmE NSURL *url = [NSURL URLWithString:@"http://a1408.g.akamai.net/5/1408/1388/2005110405/1a1a1ad948be278cff2d96046ad90768d848b41947aa1986/sample_mpeg4.mp4"]; MPMoviePlayerController *mPlayer = [[MPMoviePlayerController alloc]initWithContentURL:url]; mPlayer.view.frame = gMainView.frame; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:mPlayer]; mPlayer.shouldAutoplay = YES; mPlayer.controlStyle = MPMovieControlStyleFullscreen; [gMainView addSubview:mPlayer.view]; [mPlayer prepareToPlay]; [mPlayer setFullscreen:YES animated:YES]; [mPlayer play]; } - (void)moviePlayBackDidFinish:(NSNotification*)notification { int reason = [[[notification userInfo] valueForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey] intValue]; if (reason == MPMovieFinishReasonPlaybackEnded) { //movie finished playing } else if (reason == MPMovieFinishReasonUserExited) { //user hit the done button MPMoviePlayerController *moviePlayer = [notification object]; [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer]; if ([moviePlayer respondsToSelector:@selector(setFullscreen:animated:)]) { [moviePlayer.view removeFromSuperview]; } [moviePlayer release]; } else if (reason == MPMovieFinishReasonPlaybackError) { //error } } 

When a button is pressed, the video image is removed from the screen, but the controls are not removed from the screen, and the view is not removed from the screen.

The control comes to “// the user clicks the Finish button.) It runs the code to remove the view from the supervisor, I checked by adding logs , but the controls are not removed from the screen and the view is not removed from the screen . What am I doing wrong?

EDIT:

If I use MPMoviePlayerViewController, then it does not even wait until I click Done. Once the video is completed, it will automatically delete the view. But I do not want this.

EDIT:

If I delete "[mPlayer setFullscreen: YES animated: YES]", then when I click on "Finish" the view is completely deleted. But the video does not appear in full screen mode, and the status bar turns gray, which again is not what I do not want.

+7
source share
2 answers

The code below worked for me, hope this helps too.

 -(IBAction)playVedio:(id)sender{ mp = [[MPMoviePlayerViewController alloc] initWithContentURL:url]; [[mp moviePlayer] prepareToPlay]; [[mp moviePlayer] setUseApplicationAudioSession:NO]; [[mp moviePlayer] setShouldAutoplay:YES]; [[mp moviePlayer] setControlStyle:2]; [[mp moviePlayer] setRepeatMode:MPMovieRepeatModeOne]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(videoPlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil]; [self presentMoviePlayerViewControllerAnimated:mp]; } -(void)videoPlayBackDidFinish:(NSNotification*)notification { [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:nil]; [mp.moviePlayer stop]; mp = nil; [mp release]; [self dismissMoviePlayerViewControllerAnimated]; } 
+10
source
 - (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window { id presentedViewController = [window.rootViewController presentedViewController]; NSString *className = presentedViewController ? NSStringFromClass([presentedViewController class]) : nil; if (window && [className isEqualToString:@"AVFullScreenViewController"]) { return UIInterfaceOrientationMaskAll; } else { UIInterfaceOrientation interfaceOrientation = [UIApplication sharedApplication].statusBarOrientation; if(UIInterfaceOrientationIsPortrait(interfaceOrientation)) { } else if(UIInterfaceOrientationIsLandscape(interfaceOrientation)) { } return UIInterfaceOrientationMaskPortrait; CGRect frame = [UIScreen mainScreen].applicationFrame; CGSize size = frame.size; NSLog(@"%@", [NSString stringWithFormat:@"Rotation: %s [w=%f, h=%f]", UIInterfaceOrientationIsPortrait(interfaceOrientation) ? "Portrait" : "Landscape", size.width, size.height]); } } 
0
source

All Articles