MPMoviePlayerController deja de jugar después de unos segundos

MPMoviePlayerController deja de reproducirse después de unos segundos, este es el código que estoy usando:

 NSString *urlAddress = @"http://67.159.28.74:8730"; NSURL *url = [NSURL URLWithString:urlAddress]; MPMoviePlayerController *player = [[MPMoviePlayerController alloc]initWithContentURL:url]; player.movieSourceType = MPMovieSourceTypeStreaming; player.view.hidden = NO; [self.view addSubview:player.view]; [player prepareToPlay]; if(player){ [player play]; } 

El error que estoy recibiendo en la console es:

 2012-09-23 18:07:56.618 Reader[696:c07] [MPAVController] Autoplay: Disabling autoplay for pause 2012-09-23 18:07:56.619 Reader[696:c07] [MPAVController] Autoplay: Disabling autoplay 2012-09-23 18:07:56.638 Reader[696:c07] [MPAVController] Autoplay: Disabling autoplay for pause 2012-09-23 18:07:56.638 Reader[696:c07] [MPAVController] Autoplay: Disabling autoplay 2012-09-23 18:07:56.643 Reader[696:c07] [MPAVController] Autoplay: Enabling autoplay 2012-09-23 18:07:56.645 Reader[696:c07] [MPAVController] Autoplay: Likely to keep up or full buffer: 0 2012-09-23 18:07:56.646 Reader[696:c07] [MPAVController] Autoplay: Skipping autoplay, not enough buffenetworking to keep up. 2012-09-23 18:07:56.648 Reader[696:c07] [MPAVController] Autoplay: Likely to keep up or full buffer: 0 2012-09-23 18:07:56.648 Reader[696:c07] [MPAVController] Autoplay: Skipping autoplay, not enough buffenetworking to keep up. 2012-09-23 18:07:56.650 Reader[696:c07] [MPAVController] Autoplay: Enabling autoplay 2012-09-23 18:07:56.652 Reader[696:c07] [MPCloudAssetDownloadController] Prioritization requested for media item ID: 0 2012-09-23 18:07:58.746 Reader[696:c07] [MPAVController] Autoplay: Likely to keep up or full buffer: 0 2012-09-23 18:07:58.746 Reader[696:c07] [MPAVController] Autoplay: Skipping autoplay, not enough buffenetworking to keep up. 2012-09-23 18:07:58.747 Reader[696:c07] [MPAVController] Autoplay: _streamLikelyToKeepUp: 0 -> 1 2012-09-23 18:07:58.748 Reader[696:c07] [MPAVController] Autoplay: Likely to keep up or full buffer: 1 2012-09-23 18:07:58.748 Reader[696:c07] [MPAVController] Autoplay: Enabling autoplay` 

resuelto:

Convertí mi MPMoviePlayerController en una propiedad:

// agregar encabezado

 @property (strong,nonatomic) MPMoviePlayerController *myPlayer; 

// agregar file .m

 - (IBAction)playStream:(id)sender { NSString *urlAddress = @"http://67.159.28.74:8730"; NSURL *url = [NSURL URLWithString:urlAddress]; MPMoviePlayerController *player = [[MPMoviePlayerController alloc]initWithContentURL:url]; [player prepareToPlay]; //Remember you have to add MediaPlayer.framework to your project /*[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:player];*/ player.movieSourceType = MPMovieSourceTypeStreaming; player.view.hidden = YES; self.myPlayer = player; [self.view addSubview:self.myPlayer.view]; if(player){ [self.myPlayer play]; } } 

Tienes que establecer una variable de class como esta:

 @property (nonatomic, retain) MPMoviePlayerController *moviePlayer; 

Mi código se ve así:

 NSURL *theUrl = [[NSBundle mainBundle] URLForResource:@"test" withExtension:@"mp4"]; moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:theUrl]; [moviePlayer prepareToPlay]; [moviePlayer.view setFrame: self.view.bounds]; moviePlayer.movieSourceType = MPMovieSourceTypeFile; [self.view addSubview: moviePlayer.view]; [moviePlayer play]; 

¡Esto funciona perfecto para mí!

en xCode 4.6.1 funcionó bien.

¡Pero tuve este problema con xCode 5!

Pero esta solución es muy útil:

"La solución es que el jugador tendría que ser una variable de instancia o propiedad del controller de vista. Es decir, debemos usar la instancia de MPMoviePlayerController

@property (nonatomic, strong) MPMoviePlayerController * myMovieController; "

¡Muchas gracias al autor!

Y este es mi código:

 UIGraphicsBeginImageContext(CGSizeMake(1,1)); NSString *path = [[NSBundle mainBundle] pathForResource:@"video" ofType:@"mp4"]; NSURL *videoURL = [NSURL fileURLWithPath:path]; self.moviePlayerView = [[MPMoviePlayerController alloc] initWithContentURL:videoURL]; [self.moviePlayerView prepareToPlay]; [self.moviePlayerView.view setFrame:CGRectMake(0, 0, 320, self.view.frame.size.height/2)]; self.moviePlayerView.view.backgroundColor = [UIColor clearColor]; [self.moviePlayerView setContentURL:videoURL]; self.moviePlayerView.movieSourceType = MPMovieSourceTypeFile; self.moviePlayerView.controlStyle = MPMovieControlStyleDefault; [self.view addSubview:self.moviePlayerView.view]; self.moviePlayerView.shouldAutoplay = NO; [self.moviePlayerView play]; UIGraphicsEndImageContext(); 

Puedes intentar hacer esto justo después de instanciar tu reproductor: [player prepareToPlay]

Más información aquí: iOS 6 reproduciendo el error com.apple.coremedia.networkbuffering

Prueba esto, funciona bien para mí en ios6

 NSString *resourcePath = [[NSBundle mainBundle] pathForResource:@"ddd" ofType:@"mp4"]; NSLog(@"%@",resourcePath); NSURL *url = [NSURL fileURLWithPath:resourcePath]; NSLog(@"%@",url); MPMoviePlayerViewController *moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:url]; moviePlayer.view.frame = self.view.frame; moviePlayer.moviePlayer.shouldAutoplay=YES; moviePlayer.moviePlayer.controlStyle = MPMovieControlStyleNone; [moviePlayer.moviePlayer setFullscreen:YES animated:YES]; [self.view addSubview:moviePlayer.view]; [moviePlayer.moviePlayer play]; 

Aquí hay una interesante línea de código que te estás perdiendo.

De acuerdo con el documento de Apple

"Cuando agregue la vista de un jugador de película a la jerarquía de vista de su aplicación, asegúrese de dimensionar el marco correctamente, como se muestra aquí: http://tinyurl.com/9wgv9wc

 MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL: myURL]; [player prepareToPlay]; [player.view setFrame: myView.bounds]; // player's frame must match parent's [myView addSubview: player.view]; // ... [player play]; 

http://tinyurl.com/aeh9f84

La solución es que el jugador tendría que ser una variable de instancia o propiedad del controller de vista. Es decir, debemos usar la instancia de MPMoviePlayerController

@property (nonatomic, strong) MPMoviePlayerController * myMovieController;