Search code examples
ios6mpmovieplayercontrollerxcode4.5

Why does the MPMoviePlayerController call MPMoviePlayerPlaybackDidFinishNotification, when enter in fullsceen mode


I want to display a MPMoviePlayerViewController in full screen mode, but when the fullscreen button of the movieplayercontroller view is beeing pressed, first the MPMoviePlayerWillEnterFullscreenNotification gets called, as expacted, but than the MPMoviePlayerPlaybackDidFinishNotification is also beeing sent. As a reason it says MPMovieFinishReasonPlaybackEnded and i don't know, what i'm doing wrong. (In addition, i use iOS 6.0 and XCode 4.5.1)

My expactations are, that only the MPMoviePlayerWillEnterFullscreenNotification is beeing called.

Short explanation to the code below: The MovieplayerViewController's view is beeing displayed in a tiny subview in my content view. When tapping the fullscreen-button, it first gets displayed as fullscreen but than also calls the exit button and stops playing (no crashes, nothing else).

MPMoviePlayerViewController *playerViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:url];

   [playerViewController.moviePlayer setControlStyle:MPMovieControlStyleEmbedded];

   [playerViewController.moviePlayer setScalingMode:MPMovieScalingModeFill];

   CGRect rect = videoView.frame;

   rect.origin = CGPointZero;

   [playerViewController.view setFrame:rect];

   [playerViewController.moviePlayer prepareToPlay];


        //movie this is my contents subview, where i add the viewcontroller's view as a subbview
    [self.videoView addSubview:playerViewController.view];

    [self.videoView setHidden:NO];


    playerViewController.moviePlayer.useApplicationAudioSession = NO;

    [playerViewController.moviePlayer play];

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(moviePlayerDidFinishNotification:)
                                                 name:MPMoviePlayerPlaybackDidFinishNotification
                                               object:playerViewController.moviePlayer];
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(moviePlayerWillEnterFullscreenNotification:)
                                                 name:MPMoviePlayerWillEnterFullscreenNotification
                                               object:playerViewController.moviePlayer];    
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(moviePlayerWillExitFullscreenNotification:)
                                                 name:MPMoviePlayerWillExitFullscreenNotification
                                               object:playerViewController.moviePlayer];

        //i store the movieplayer in a property, so i can use it for further operations
    self.myPlayer = playerViewController;

    [playerViewController release];

And thats it!

When the resize (or fullscreen) button is being pressed, the moviePlayerDidFinishNotification: method also is being called

- (void)moviePlayerDidFinishNotification:(NSNotification*) aNotification {

    int reason = [[[aNotification userInfo] valueForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey] intValue];

    if (reason == MPMovieFinishReasonPlaybackEnded) {

        //movie finished playin

//in debug mode, it stops right at the NSLog

        NSLog(@"");
    }

    else if (reason == MPMovieFinishReasonUserExited) {

        //user hit the done button

    }

    else if (reason == MPMovieFinishReasonPlaybackError) {

        //error

    }

.. }

Is there something i do wrong or is there probably a change since iOS 6.0?


Solution

  • Ok, seems to be that there are some problems in the MPMoviePlayerViewController. What helped is to simply us the MPMoviePlayerController only.