MPMoviePlayerController stops playing after a few seconds

MPMoviePlayerController stops playing after a few seconds, this is the code I use:

 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]; } 

Error logging into the console:

 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 buffered 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 buffered 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 buffered 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` 
+7
source share
7 answers

I decided:

I turned my MPMoviePlayerController into a property:

// add title

 @property (strong,nonatomic) MPMoviePlayerController *myPlayer; 

// add to the .m file

 - (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]; } } 
+9
source

You must set the class variable as follows:

 @property (nonatomic, retain) MPMoviePlayerController *moviePlayer; 

My code is as follows:

 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]; 

This works great for me!

+8
source

on xCode 4.6.1 it worked fine.

But I had this problem with xCode 5!

But this solution is very useful:

"The solution is that the player must have an instance variable or a view controller property, that is, we must use the MPMoviePlayerController instance

@property (non-atomic, strong) MPMoviePlayerController * myMovieController; "

Thanks to the author very much!

And this is my code:

 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(); 
+2
source

You can try to do this right after creating your player: [player prepareToPlay]

Additional information here: iOS 6 streaming player com.apple.coremedia.networkbuffer error

+1
source

Try this, it works well for me in 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]; 
+1
source

Here is an interesting line of code that you are missing.

According to Apple Doc

"When you add movie viewing to the presentation hierarchy of your applications, make sure the frame size is correct, as shown below: http://tinyurl.com/9wgv9wc

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

http://tinyurl.com/aeh9f84

0
source

The solution is that the player must have an instance variable or a view controller property. those. we must use an instance of MPMoviePlayerController

@property (non-atomic, strong) MPMoviePlayerController * myMovieController;

0
source

All Articles