AVQueuePlayer does not advance to next item in iOS 8

I am using AVQueuePlayer to play multiple videos, everything works fine in iOS 6 and 7. However, in iOS 8, when the current AVPlayerItem finishes playing the next video, it does not play. Placing an observer in the currentItem property of the queue shows that the queue has the next video as the current item, as expected, it just doesn't play (even with explicit playback calls).

Does anyone have any idea what might be happening and how to fix it? Does anyone else have this problem?

+3


source to share


3 answers


I had exactly the same problem and spent ten hours on this ...
But now this is fixed by adding the "insertItem" method to the main thread. Thus, I have the player as a property:

@property AVQueuePlayer * player;

      

I just start it like this:

_player = [[AVQueuePlayer alloc] init];

      

And here is my method for adding items from the 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 it works, but I really don't understand why ... So if anyone has an answer ...

But also, if that doesn't work for you, try adding an observer to the player (and / or your playerItem). You can add an observer like this:

[_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.

+1


source


avplayer should always be available on the main stream. This is nothing new in iOS8, but Apple may have changed its use of streams, so you see the problem more often than in iOS7.

To allow safe access to non-atomic properties of players while dynamic changes to the play state can be reported, you must serialize access using a recipient notification queue. In general, this serialization is naturally achieved by calling various AVPlayers methods on the main thread or queue.



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

0


source


I had the same problem. After a few hours of trial period, I found that if some of the items in the queue have different encryption methods, the player will stop.

For example, if a player has just finished playing an encrypted stream, and the next item in the queue was unencrypted, the player will not move on to the next item.

0


source







All Articles