Question

I have the following code to play a video

 moviePlayer1 =[[MPMoviePlayerController alloc] initWithContentURL:firstMovieURL1];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(doneButtonClicked) name:MPMoviePlayerWillExitFullscreenNotification object:nil];
    [[moviePlayer1 view] setFrame: [self.view bounds]];  // frame must match parent view
    [self.view addSubview: [moviePlayer1 view]];

    [moviePlayer1 play];




-(void)doneButtonClicked
{
    NSLog(@"doneButtonClicked ...");

    [moviePlayer1 stop];
    [moviePlayer1.view removeFromSuperview];

}

If I use the above code my screen looks like this. I have to click on the little arrow icon and then the screen again to show controls (forward/backwards/done button)

enter image description here

so what I did was add this controlStyle to my code. I see all the buttons now as soon as the player is launched but and now my done button doesn't close the window instead it just pauses the movie. What happened?

moviePlayer1.controlStyle=MPMovieControlStyleFullscreen;
[moviePlayer1 play];

enter image description here

Was it helpful?

Solution

This is how you do it. God forbid if apple makes this logic any easy on us.

[[moviePlayer1 view] setFrame: [self.view bounds]];  // frame must match parent view
    [self.view addSubview: [moviePlayer1 view]];

    moviePlayer1.controlStyle=MPMovieControlStyleFullscreen;

    [moviePlayer1 prepareToPlay];
    [moviePlayer1 play];

    //use this instead
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(doneButtonClicked:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];


-(void)doneButtonClicked:(NSNotification*)notification
{
    NSLog(@"doneButtonClicked ...");

    NSNumber *reason = [notification.userInfo objectForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey];

    if ([reason intValue] == MPMovieFinishReasonUserExited)
    {

        // done button clicked!

        [moviePlayer1 stop];
        [moviePlayer1.view removeFromSuperview];

    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top