I use AVPlayer to play tracks from the Internet. There are always a few tracks in my playlist. So, to determine the action that will be performed when the current track reaches its end, I use the KVO mechanism and register an observer for the published AVPlayerItemDidPlayToEndTimeNotification.
if (_player.currentItem.status == AVPlayerItemStatusReadyToPlay) { [self play]; [NSNotificationCenter defaultCenter] addObserver:self selector:@selector(itemReachedEnd:) name:AVPlayerItemDidPlayToEndTimeNotification object:_player.currentItem]; }
When the notification is sent, the itemReachedEnd method is called:
- (void) itemReachedEnd:(NSNotification *) notification { dispatch_async(dispatch_get_main_queue(), ^{
The fact is that sometimes this method is called when the element has not finished playing, and I have the current track, which was switched before it was played to the end. I do not understand why this is happening.
Please tell me what am I doing wrong? Maybe I need to take into account some other properties of AVPlayerItem before switching tracks?
Update: I researched that the current position of the current track is not equal to the current track duration. Then why does the player think that the current element has finished the game?
Tanya source share