MPMoviePlayerController audio solo después de que la aplicación se activó

Utilizo MPMoviePlayerController en mi aplicación y cuando MPMoviePlayerController el button de inicio y luego abro la aplicación de nuevo, el reproductor continúa la reproducción, pero solo el audio. En lugar del video, el usuario ve una pantalla negra.

Este error solo está en el dispositivo (iOS 5.0, quizás versiones anteriores también). En el simulador está bien.

¿Algunas ideas?

Código que crea la instancia de MPMoviePlayerController y lo agrega a la vista:

 if (!self.moviePlayerController) { MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:movieURL]; if (player) { /* Save the movie object. */ [self setMoviePlayerController:player]; /* Register the current object as an observer for the movie notifications. */ [self installMovieNotificationObservers]; player.shouldAutoplay = YES; player.controlStyle = MPMovieControlStyleNone; player.scalingMode = MPMovieScalingModeAspectFit; player.useApplicationAudioSession = NO; [player setContentURL:movieURL]; [player prepareToPlay]; if ([player respondsToSelector:@selector(setAllowsAirPlay:)]) { [player setAllowsAirPlay:YES]; } [player setMovieSourceType:sourceType]; [[player view] setFrame:[self.view bounds]]; [self.view addSubview: [player view]]; [self.view sendSubviewToBack:[player view]]; [player release]; } } 

movieURL – es el enlace a mp4 de esta forma: http: //host.domain/filename.mp4 ¿ tal vez MPMoviePlayerController no funciona correctamente con el tipo de fuente mp4 sobre http?

Solución

En este caso, todo está bien:

 - (void)applicationWillResignActiveNotification:(NSNotification*)notification { if (self.moviePlayerController.playbackState == MPMoviePlaybackStatePlaying) { self.playerState = PlayerStatePlaying; } else if (self.moviePlayerController.playbackState == MPMoviePlaybackStatePaused) { self.playerState = PlayerStatePaused; self.playbackTimeBeforeBackground = self.moviePlayerController.currentPlaybackTime; [self.moviePlayerController pause]; } - (void)applicationDidBecomeActiveNotification:(NSNotification*)notification { self.moviePlayerController.currentPlaybackTime = -1; if (self.playerState & PlayerStatePlaying) { [self performSelector:@selector(startPlayerAfterDelayPause:) withObject:nil afterDelay:0.2]; } else if (self.playerState & PlayerStatePaused) { [self performSelector:@selector(startPlayerAfterDelayPause:) withObject:[NSNumber numberWithBool:YES] afterDelay:0.2]; } } - (void)startPlayerAfterDelayPause:(NSNumber *)isPause{ self.moviePlayerController.currentPlaybackTime = self.playbackTimeBeforeBackground; if ([isPause boolValue] == YES) { [self.moviePlayerController pause]; } else { [self.moviePlayerController play]; } } 

testing este código:

 NSString *path=[bundle pathForResource:@"ImageHomeAnimation" ofType:@"mp4"]; MPMoviePlayerController *mp = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:path]]; self.player1= mp;//[[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:path]]; [mp release]; self.player1.view.frame = CGRectMake(0, -20, 320,480); self.player1.view.backgroundColor=[UIColor clearColor]; [self.view addSubview:self.player1.view]; self.player1.fullscreen=YES; [self.player1 setRepeatMode:MPMovieRepeatModeNone]; self.player1.controlStyle=MPMovieControlStyleNone; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieFinishedCallback) name:MPMoviePlayerPlaybackDidFinishNotification object:self.player1]; [self.player1 prepareToPlay]; [self.player1 play]; -(void)movieFinishedCallback { [self.player1.view removeFromSuperview]; }