-1

我使用MPMoviePlayerViewController来播放来自服务器的视频流,其他一切工作都很流畅。我的问题是,当我播放视频时,它会自动播放,如果没有可用的可播放内容,将自动进入暂停状态,并且在获取内容后不会播放。MPMoviePlayer在流式传输时自动暂停

movieController = [[MPMoviePlayerViewController alloc] init]; 
movieController.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming; 
[movieController.moviePlayer setContentURL:mediaURL]; 
[movieController.moviePlayer prepareToPlay]; 
[[NSNotificationCenter defaultCenter] addObserver:self 
             selector:@selector(moviePlayBackDidFinish:) 
              name:MPMoviePlayerPlaybackDidFinishNotification 
              object:nil]; 
[movieController.moviePlayer setControlStyle:MPMovieControlStyleFullscreen]; 
[movieController.moviePlayer setFullscreen:YES]; 
[movieController.moviePlayer setShouldAutoplay:YES]; 
[movieController.moviePlayer play]; 
[self presentMoviePlayerViewControllerAnimated:movieController]; 

这是我的代码,用于播放从mediaURL给出的网址的视频。我试图添加MPMoviePlayerPlaybackStateDidChangeNotification检查状态更改为MPMoviePlaybackStatePaused,它也工作正常。还检查MPMovieLoadStateMPMovieLoadStatePlaythroughOK使用MPMoviePlayerLoadStateDidChangeNotification问题是,自动暂停后没有得到MPMovieLoadStatePlaythroughOKThis link

也有什么办法可以得到暂停按钮水龙头以外的MPMoviePlayerPlaybackStateDidChangeNotification,因为通知也因其他原因被解雇。

回答

0

我在MPMoviePlayerViewController中的默认播放/暂停按钮上方添加了一个透明按钮,如下所示。

CGRect frame = CGRectZero; 
CGFloat width = 100, height= 50; 
frame.origin.x = CGRectGetHeight(movieController.moviePlayer.view.frame)/2 - (width/2); 
frame.origin.y = CGRectGetWidth(movieController.moviePlayer.view.frame) - height; 
frame.size = CGSizeMake(width, height); 
UIButton* playButton = [[UIButton alloc] initWithFrame:frame]; 
playButton.backgroundColor = [UIColor clearColor]; 
[playButton addTarget:self action:@selector(playButtonTapped:) forControlEvents:UIControlEventTouchUpInside]; 
[movieController.moviePlayer.view addSubview:playButton]; 


- (void) playButtonTapped:(UIButton*) sender { 
if (APP_DELEGATE.movieController.moviePlayer.playbackState == 1) { 
    [APP_DELEGATE.movieController.moviePlayer pause];   
} 
else if (APP_DELEGATE.movieController.moviePlayer.playbackState == 2) 
{ 
    [APP_DELEGATE.movieController.moviePlayer play];   
} 
}