我正在使用MPMoviePlayerViewController
播放来自服务器的视频流,其他一切工作顺利。我的问题是,当我播放视频时,它会自动播放,如果没有可播放的内容,则自动进入暂停状态,并且在加载内容后不播放。
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
,它也正常工作。同时使用MPMovieLoadState
使用MPMovieLoadStatePlaythroughOK
检查MPMoviePlayerLoadStateDidChangeNotification
,问题是自动暂停后无法获得MPMovieLoadStatePlaythroughOK
。This link
除了MPMoviePlayerPlaybackStateDidChangeNotification
之外,是否有任何方法可以获得暂停按钮,因为其他原因也会触发通知。
答案 0 :(得分: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];
}
}