AVQueuePlayer视频图像冻结,沉默通知

时间:2013-01-19 18:00:15

标签: iphone ios avqueueplayer

我正在使用一个s3存储桶上的一组编码视频构建AVQeueue播放器,使用AVPlayerActionAtItemEndAdvance按顺序播放视频;

  • 视频全部采用相同的分辨率和编解码器编码
  • 他们都经过测试很好玩
  • 在某些设备上,此解决方案可以正常使用
  • 以下问题在IOS 5.x和6.x上都会被注意到
  • 一直在尝试检查主线程中的所有内容。 (很可能是问题)

问题:在模拟器和某些设备上(注意4和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];

    }

0 个答案:

没有答案