我在单元格内部有一个AVPlayer
的集合视图,AVPlayer
在循环中开始播放AVPlayerItem
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
被调用。这很好但问题是在AVPlayer
播放项目几次之后视频不再显示但我能听到它的声音。
我还为每个播放的项目添加了@"playbackBufferFull"
值的观察者:
[item addObserver:self forKeyPath:@"playbackBufferFull" options:NSKeyValueObservingOptionNew context:nil];
我注意到当视频停止时,值@"playbackBufferFull"
的观察者方法被调用,首先我想知道是什么原因导致缓冲区变满,第二个也是最重要的是我怎样才能恢复视频停止时的AVPlayer
;
我试着调用[cell.videoPlayer play];
并用新的项替换它并且它没有用,观察者方法:
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object
change:(NSDictionary *)change context:(void *)context {
if ([object isKindOfClass:[AVPlayerItem class]] && [keyPath isEqualToString:@"playbackBufferFull"])
{
//this method is get called when the video stop showing but i can still hear it
//how can i resume the video?
}
}
答案 0 :(得分:1)
我的解决方案是:
首先在AVPlayerItemPlaybackStalledNotification
或...
viewDidLoad
的观察
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(playerItemDidReachEnd:)
name:AVPlayerItemPlaybackStalledNotification
object:self.avPlayer.currentItem];
-(void)playerItemDidReachEnd:(NSNotification*)noti
{
//thisisn't good way but i can't find the best way for detect best place for resume again.
NSLog(@"\n\n give Error while Streaminggggg");
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self.avPlayer play];
});
}
<强> BUT 强>
也许你可以找到再次调用play方法的最佳方法!
请检查你得到AVPlayerStatusReadyToPlay
keypatch?
如果你得到,你可以在那里调用play
方法。
请通知我结果