我正在使用 MPMoviePlayerController
播放视频。在以下情况下,我遇到黑屏,对控件的点击没有反应:
- 用户点击快进按钮
- 用户点击倒带按钮
- 用户长按并快进到视频结尾
所有其他控件都按预期工作。
请注意,长按快进和快退会按预期工作。
我确实查看了下面链接中的文档。有关于用户向前和向后搜索(例如,长按)的通知;分别为 MPMoviePlaybackStateSeekingForward
和 MPMoviePlaybackStateSeekingBackward
。也就是说,在搜索按钮上没有简单_点击_通知。
链接是“Here”。
为了完整起见,下面是我用来调用播放器的代码。没什么特别的;当视频结束时(观察 MPMoviePlayerPlaybackDidFinishNotification
),我倒回到开头。
NSString *path = [[NSBundle mainBundle] pathForResource:@"catSleeping" ofType:@mp4"];
_videoPlayer = [[MPMoviePlayerController alloc]
initWithContentURL:[NSURL fileURLWithPath:path]];
[_videoPlayer prepareToPlay];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:_videoPlayer];
_videoPlayer.controlStyle = MPMovieControlStyleFullscreen;
_videoPlayer.shouldAutoplay = YES;
[self.view addSubview:_videoPlayer.view];
[_videoPlayer setFullscreen:YES animated:YES];
[_videoPlayer play];
}
- (void) moviePlayBackDidFinish:(NSNotification*)notification {
MPMoviePlayerController *player = [notification object];
player.currentPlaybackTime = 0.1;
[player stop];
[player play];
[player pause];
}
有什么想法吗?
tyvm 基思:)
最佳答案
单击快进或快退按钮时,播放器加载状态未知。您需要处理 MPMoviePlayerLoadStateDidChangeNotification 并重新加载视频路径并再次准备播放。
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(playerLoadStateChanged:)
name:MPMoviePlayerLoadStateDidChangeNotification
object:nil];
- (void)playerLoadStateChanged:(NSNotification *)notification {
MPMovieLoadState loadState = _videoPlayer.loadState;
if(loadState == MPMovieLoadStateUnknown) {
_videoPlayer.contentURL = [NSURL fileURLWithPath:self.path]
[_videoPlayer prepareToPlay];
}
}
关于ios - MPMoviePlayerController:Seek Button 点击卡住视频 - 黑屏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23701154/