我正在从 s3 存储桶上的一组编码视频构建 AVQeueue 播放器,使用 AVPlayerActionAtItemEndAdvance 按顺序播放视频;
- 视频都以相同的分辨率和编解码器编码
- 他们都经过测试很好玩
- 在某些设备上,以下解决方案可以正常工作
- 在 IOS 5.x 和 6.x 上都注意到以下问题
- 一直在尝试检查主线程中的所有操作。(很可能是问题)
问题:在模拟器和某些设备上(在 4s 和 5 上注意到)在 x 数量的视频(x 有时不可预测,但通常是 3、4)之后,视频仅以声音播放并终止队列并且不会抛出“playerItemDidReachEnd “ 通知。应用程序不会崩溃或冻结。没有从“AVPlayerItemStatusFailed”或“AVPlayerItemStatusUnknown”收到错误
如果有人有这个问题的经验,请分享。
代码:-(void)addObservers {
dispatch_async(dispatch_get_main_queue(),
^{
for(int i = 0; i < [self.videodata count]; i++) {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(playerItemDidReachEnd:)
name:AVPlayerItemDidPlayToEndTimeNotification
object:[self.videodata objectAtIndex:i]];
[[self.videodata objectAtIndex:i] addObserver:self forKeyPath:@"status" options:NSKeyValueObservingOptionNew context:nil];
[[self.videodata objectAtIndex:i] addObserver:self forKeyPath:@"playbackBufferEmpty" options:NSKeyValueObservingOptionNew context:nil];
[[self.videodata objectAtIndex:i] addObserver:self forKeyPath:@"playbackLikelyToKeepUp" options:NSKeyValueObservingOptionNew context:nil];
}
});
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *) change context:(void *)context
{
if ([object isKindOfClass:[AVPlayerItem class]])
{
AVPlayerItem *item = (AVPlayerItem *)object;
if ([keyPath isEqualToString:@"status"])
{ //yes->check it...
switch(item.status)
{
case AVPlayerItemStatusFailed:
{
[TestFlight passCheckpoint:@"AV FAILED"];
NSError *error = [item error];
NSLog(@"playback error is %@", error);
break;
}
case AVPlayerItemStatusReadyToPlay:
NSLog(@"player item status is ready to play");
break;
case AVPlayerItemStatusUnknown:
{
[TestFlight passCheckpoint:@"AV STATUS UNKNOWN"];
break;
}
}
}
else if (item == [self.queuePlayer currentItem] && [keyPath isEqualToString:@"playbackBufferEmpty"])
{
if (item.playbackBufferEmpty)
{
[loadingView show:YES];
}
}
else if(item == [self.queuePlayer currentItem] && [keyPath isEqualToString:@"playbackLikelyToKeepUp"])
{
[self.queuePlayer play];
[loadingView hide:YES];
}
}
}
- (void)playerItemDidReachEnd:(NSNotification *)notification {
NSLog(@"ended video %i " , (int)self.currentItem);
AVPlayerItem *p = [notification object];
[p seekToTime:kCMTimeZero];
}