tags:

views:

31

answers:

2

I have a single view app with 5 buttons and when one of the buttons is pressed, the player slides up over the original view and begins playing the video in fullscreen (as it should).

All works great with the exception of when pressing the Fullscreen/Minimize icon (the two diagonal arrows pointing to each other next to the play back controls). When pressing this, the original view with the five buttons slides up over the video player. The problem is the video is still playing underneath the original view. I would really like to eliminate the Fullscreen/Minimize icon but from I can tell, that does not seem possible. So... I am thinking, I might be able to use an observer to listen to when the Fullscreen/Minimize icon is pressed and I can do what I need to. I just can not find anything solid on how to do this. Any help/direction would be greatly appreciated.

Here is my current code...

-(IBAction)playvideo {

 NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Megamind" ofType:@"mov"]];
 MPMoviePlayerViewController * playerController = [[MPMoviePlayerViewController alloc] initWithContentURL:url];

 [self presentMoviePlayerViewControllerAnimated:(MPMoviePlayerViewController *)playerController];

 playerController.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
 [playerController.moviePlayer play];
 [playerController release];
 playerController=nil;
}

- (void)moviePlayerWillExitFullscreen:(NSNotification *)theNotification {

 MPMoviePlayerController *playerController = [theNotification object];
 [[NSNotificationCenter defaultCenter] addObserver:self
            selector:@selector(moviePlayerWillExitFullscreen:)
             name:MPMoviePlayerWillExitFullscreenNotification
              object:nil];

 [playerController stop];
 [self dismissMoviePlayerViewControllerAnimated];
}
A: 

Put this line just after the init of your MPMoviePlayer :

[[NSNotificationCenter defaultCenter] addObserver:self
            selector:@selector(moviePlayerWillExitFullscreen:)
             name:MPMoviePlayerWillExitFullscreenNotification
              object:nil];
MathieuF
Thanks for the reply. Unfortunately, no luck. So I am wondering if 1) my observer is coded correctly/working or 2) that it may not be possible to listen for when the Fullscreen/Embed presses is possible. any other thoughts or direction would be most welcome.
joeyd
I have edited my answer
MathieuF
Thanks once again for the reply. Looks like the way I have it... none of the notices aside from didFinish are responding. I just tried your edit and still no luck. However, I did find another solution. Ill post the answer in a bit.
joeyd
A: 

I did find a solution and my lack of knowledge put me in a situation where I do not fully understand why it works this way. My apologies for not having a thorough reasoning. In my original code... the MPMoviePlayerWillExitFullscreenNotification was not answering to taps. This is true for MPMoviePlayerDidExitFullscreenNotification as well. What was answering was MPMoviePlayerPlaybackDidFinishNotification. Here is teh working code in knowing that the MPMoviePlayerPlaybackDidFinishNotification was working and also applied to the Fullscreen/Embed presses.

-(IBAction)playvideo {

NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Megamind" ofType:@"mov"]];
MPMoviePlayerViewController * playerController = [[MPMoviePlayerViewController alloc] initWithContentURL:url];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieFinishedPlayback:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];

[self presentMoviePlayerViewControllerAnimated:(MPMoviePlayerViewController *)playerController];

playerController.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
[playerController.moviePlayer play];
[playerController release];
playerController=nil;
NSLog(@"playvideo");

}

  • (void)movieFinishedPlayback:(NSNotification*)notification {

        MPMoviePlayerController *playerController = [notification object];
        [playerController pause];
        [self dismissMoviePlayerViewControllerAnimated];
    

}

joeyd
Apologies... I can not seem to get the code block above to stay formatted using the post editor. Kept breaking no matter how I entered it. But this is the code that got my app working.
joeyd