我正在使用MPMoviePlayerController
从网址播放.m3u
类型的流媒体视频。他们的视频播放器发布完美,视频开始播放也很完美,但只要按下向前搜索或向下搜索或开始查看前进按钮,视频就会完全停止/冻结。之后,我可以点击Done
关闭播放器或清除progress bar
,它将返回播放视频。但我无法点击play/pause
或至少似乎没有做任何事情。
我花了很长时间在网上寻找答案或者至少提示,所以我可以朝着正确的方向解决这个问题但不是运气。所以,我真的希望有人可以帮忙解决这个问题。顺便说一句,这只发生在iOS 8+上,目前我在iOS 8.1中进行测试。
这是我创建播放器并将视频加载到它的方式。
NSURL *videoURL = [NSURL URLWithString:self.video.flvurl];
self.moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL: videoURL];
self.moviePlayer.controlStyle = MPMovieControlStyleFullscreen;
self.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
self.moviePlayer.shouldAutoplay = NO;
self.moviePlayer.fullscreen = YES;
self.moviePlayer.repeatMode = YES;
self.moviePlayer.view.backgroundColor = [UIColor blackColor];
self.moviePlayer.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.moviePlayer.view.frame = self.containerView.frame;
[self.view addSubview:self.moviePlayer.view];
[self.moviePlayer prepareToPlay];
[self.moviePlayer play];
我尝试过使用多个不同的通知,看看我是否可以在其中一个中捕捉到这个,但根本没有运气。到目前为止,我已对所有这些通知进行了测试。我已将此添加到self.moviePlayer
,并且self.moviePlayer.view
中的任何一个都没有运气。
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(willResignActive:)
name:UIApplicationWillResignActiveNotification
object:self.moviePlayer.view];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(videoPlaybackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:self.moviePlayer.view];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(videoStartedPlaying:)
name:MPMoviePlayerNowPlayingMovieDidChangeNotification
object:self.moviePlayer.view];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(videoLoadState:)
name:MPMoviePlayerLoadStateDidChangeNotification
object:self.moviePlayer.view];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(videoPlaybackState:)
name:MPMoviePlayerPlaybackStateDidChangeNotification
object:self.moviePlayer.view];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(videoPlaybackUserInfoKey:)
name:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey
object:self.moviePlayer.view];
好吧,如果您需要更多相关代码,请告诉我们。我真的需要一些帮助..提前谢谢。
答案 0 :(得分:0)
这段代码对我有用,但只是为了摆脱冻结。注册MPMoviePlayerLoadStateDidChangeNotification,就像您上面所做的那样。在回调方法中,我只是将电影播放器contentURL设置为我在开始时初始化它的原始URL,并将电影播放器设置为再次播放。
此功能是当您全屏点击NEXT或BACK按钮时,视频将从头开始重新开始播放。这可能不太理想,因为用户可能没想到这一点,但至少它会阻止它冻结。我目前正在努力寻找更好的解决方法。
- (void) videoLoadState:(NSNotification *)notification
{
MPMovieLoadState loadState = moviePlayer.loadState;
if(loadState == MPMovieLoadStateUnknown)
{
NSLog(@"Movie Load state is unknown");
moviePlayer.contentURL = currentlyPlayingVideoURL;
[moviePlayer prepareToPlay];
}
}
如果你在这个方法中检查MPMoviePlaybackState的值,当按下NEXT或BACK时它总是MPMoviePlaybackStateStopped,所以我不知道如何处理它......