MPMoviePlayerController autoplays when streaming -

2019-05-05 18:34发布

问题:

I'm streaming a movie on the iPad. If I just load a mp4 file, the player doesn't autostart - but with the example m3u8, it insists on autostarting. Has anyone encountered this? Am I doing something wrong?

- (id)initWithVideo:(VideoDO*)video frame:(CGRect)rect { 
NSURL* videoURL = [NSURL     URLWithString:@"http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8"]; // With    this URL, player starts automatically
 self.moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];

 moviePlayer.shouldAutoplay = NO;
 moviePlayer.controlStyle = MPMovieControlStyleEmbedded;
 moviePlayer.view.frame = rect;
 moviePlayer.view.backgroundColor = [UIColor blackColor]; 
 [moviePlayer prepareToPlay];  

 self.view = moviePlayer.view;   
 [moviePlayer stop];

 [[NSNotificationCenter defaultCenter] addObserver:self    selector:@selector(movieFinishedCallback:) name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer];
 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieChangedLoadState:) name:MPMoviePlayerLoadStateDidChangeNotification object:moviePlayer];


 return self;
} 

回答1:

Here you can do [moviePlayer pause]; instead of [moviePlayer stop]; and remove the line [moviePlayer prepareToPlay]; from the code and it will work. Let me know if any problem.