简体   繁体   English

AVQueuePlayer没有进入iOS 8中的下一个项目

[英]AVQueuePlayer not advancing to next item in iOS 8

I am using AVQueuePlayer to play a few videos, everything works fine in iOS 6 & 7. However, in iOS 8, when the current AVPlayerItem finishes playing the next video does not play. 我正在使用AVQueuePlayer播放一些视频,在iOS 6和7中一切正常。但是,在iOS 8中,当前AVPlayerItem完成播放时,下一个视频无法播放。 Placing an observer on the queue's currentItem property shows the the queue has the next video set as its current item as expected, it just does not play (even with explicit play calls). 将观察者放置在队列的currentItem属性上会显示队列将下一个视频集作为其当前项目按预期进行,它只是不播放(即使使用显式播放调用)。

Does anyone have any insight into what might be happening and how to fix it? 有没有人能够了解可能发生的事情以及如何解决这个问题? Has anyone else come across this issue? 还有其他人遇到过这个问题吗?

I had exactly the same issue and I wasted ten hours on this... 我有完全相同的问题,我浪费了十个小时......
But it fixed now by adding the "insertItem" method into the main thread. 但现在通过在主线程中添加“insertItem”方法来修复它。

So I have my player as a property : 所以我把我的玩家作为财产:

@property AVQueuePlayer * player;

I just init it like this : 我只是这样初始化它:

_player = [[AVQueuePlayer alloc] init];

And here is my method to add items from a path : 这是我从路径添加项目的方法:

- (void)addInQueuePlayerFile:(NSString *)path {
   AVAsset * asset = [AVAsset assetWithURL:[[NSURL alloc] initFileURLWithPath:path]];
   AVPlayerItem * playerItem = [AVPlayerItem playerItemWithAsset:asset];

   dispatch_async(dispatch_get_main_queue(), ^{
      [_player insertItem:playerItem afterItem:nil];
   });
}

So its working but I don't really understand why... So if someone has an answer... 所以它的工作,但我真的不明白为什么......所以,如果有人有答案......

But also if this doesn't work for you, try to add an observer to your player (and/or your playerItem). 但是如果这对您不起作用,请尝试向您的播放器(和/或您的playerItem)添加观察者。 You can add an observer like that : 您可以添加这样的观察者:

[_player addObserver:self forKeyPath:@"status" options:0 context:nil]

And catch it with this method : 并用这种方法捕捉它:

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
   if (object == _player && [keyPath isEqualToString:@"status"]) {
      if (_player.status == AVPlayerStatusFailed) {
         NSLog(@"AVPlayer Failed");
      } else if (_player.status == AVPlayerStatusReadyToPlay) {
         NSLog(@"AVPlayer item Ready to Play");
      } else if (_player.status == AVPlayerStatusUnknown) {
         NSLog(@"AVPlayer item Unknown");
      }
   }
}

Let me know if this work for you. 如果这对您有用,请告诉我。

The avplayer should always be accessed on the main thread. 应始终在主线程上访问avplayer。 This is nothing new to iOS8 but perhaps Apple changed how threads are used so you're seeing the issue more often than in iOS7. 这对iOS8来说并不是什么新鲜事,但也许Apple改变了线程的使用方式,所以你比iOS7更经常地看到这个问题。

To ensure safe access to a player's nonatomic properties while dynamic changes in playback state may be reported, you must serialize access with the receiver's notification queue. 为了确保在报告播放状态的动态变化时安全访问播放器的非原子属性,您必须使用接收器的通知队列序列化访问。 In the common case, such serialization is naturally achieved by invoking AVPlayer's various methods on the main thread or queue. 在通常情况下,通过在主线程或队列上调用AVPlayer的各种方法,自然可以实现这种序列化。

https://developer.apple.com/library/ios/documentation/AVFoundation/Reference/AVPlayer_Class/index.html https://developer.apple.com/library/ios/documentation/AVFoundation/Reference/AVPlayer_Class/index.html

I had the same problem. 我有同样的问题。 After several hours of trial, I found that if some of the items in queue have different encryption methods, the player would stall. 经过几个小时的试用,我发现如果队列中的某些项目有不同的加密方法,播放器就会停止。

For example, if the player just finished playing an encrypted stream, and the next item in queue was unencrypted, the player is not going to move on to the next item. 例如,如果播放器刚刚播放完加密的流,并且队列中的下一个项目未加密,则播放器不会继续播放下一个项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM