MPMoviePlayerViewController turns black when entering background

I have a problem with MPMoviePlayerViewController, when the application enters the background, and then I start it again or go to another viewing mode, the movie turned black! I have a movie that plays in the background of my menus, here is my code:

EIDTED CODE:

    -(void)viewDidLoad {
        [self moviePlayer2];
    } 

   - (void) moviePlayer2 {



    NSString *path = [[NSBundle mainBundle] pathForResource:@"cloud" ofType:@"mp4"];
    player = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL fileURLWithPath:path]];
    player.view.userInteractionEnabled = YES;    
    player.moviePlayer.repeatMode = YES;
    player.moviePlayer.scalingMode = MPMovieScalingModeFill;
    player.moviePlayer.controlStyle = MPMovieControlStyleNone;

    [[NSNotificationCenter defaultCenter] addObserver:self 
                                             selector:@selector(moviePlayBackStateChange:) 
                                                 name:MPMoviePlayerPlaybackStateDidChangeNotification
                                               object:[player moviePlayer]];

     [[player moviePlayer] play];

    [self.view addSubview:player.view]; 

}


-(void) moviePlayBackStateChange: (NSNotification *) note {

    [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackStateDidChangeNotification object:[player moviePlayer]];

    [[player moviePlayer] play];

    //[player release];
    NSLog(@"FINISHED");
}

Thank you.

+5
source share
2 answers

I think you might need to add the codes below:

[[NSNotificationCenter defaultCenter] addObserver:self 
                                             selector:@selector(moviePlayBackStateChange:) 
                                                 name:MPMoviePlayerPlaybackStateDidChangeNotification
                                               object:[player moviePlayer]];

moviePlayBackStateChange. , , , , , . , . .

[[player moviePlayer] play];

. , , :

-(void) pauseMovieInBackGround
{
   [player moviePlayer] pause];
   [player.view removeFromSuperview];
}
-(void) resumeMovieInFrontGround
{
   [self.view addSubview:player.view];
   [[player moviePlayer] play];
}

, .

+3

:

[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:[player moviePlayer]];
[player release];

:

[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:[player moviePlayer]];
[movieController.view removeFromSuperview];
[player release];

, : D

+1

All Articles