Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/118.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios AVPlayerItemDidPlayToEndTimeNotification在项目未完成播放时发布_Ios_Objective C_Avplayer - Fatal编程技术网

Ios AVPlayerItemDidPlayToEndTimeNotification在项目未完成播放时发布

Ios AVPlayerItemDidPlayToEndTimeNotification在项目未完成播放时发布,ios,objective-c,avplayer,Ios,Objective C,Avplayer,我正在使用AVPlayer从web播放曲目。在我的播放列表中总是有几首曲目。 因此,为了定义当前曲目结束时将采取的操作,我使用KVO机制并注册一个AVPlayerItemDidPlayToEndTimeNotification的观察者 if (_player.currentItem.status == AVPlayerItemStatusReadyToPlay) { [self play]; [NSNotificationCenter defaultC

我正在使用AVPlayer从web播放曲目。在我的播放列表中总是有几首曲目。 因此,为了定义当前曲目结束时将采取的操作,我使用KVO机制并注册一个AVPlayerItemDidPlayToEndTimeNotification的观察者

    if (_player.currentItem.status == AVPlayerItemStatusReadyToPlay)
    {
       [self play];
       [NSNotificationCenter defaultCenter] addObserver:self selector:@selector(itemReachedEnd:) name:AVPlayerItemDidPlayToEndTimeNotification object:_player.currentItem];
    }
发布通知时,将调用itemReachedEnd方法:

- (void) itemReachedEnd:(NSNotification *) notification
{
dispatch_async(dispatch_get_main_queue(), ^{
    //switching to the next track
}
问题是,有时当项目还没有完成播放,并且在播放到结束之前切换了当前曲目时,会调用此方法。我不明白为什么会这样

请告诉我,我做错了什么?在切换曲目之前,我可能需要考虑一些其他AVPlayerItem属性


Upd:我发现当前轨道的当前位置不等于当前轨道的持续时间。那么为什么玩家认为当前物品已经玩完了呢?

不是你问题的真实答案,但是你有没有研究过?这应该完全满足您的需要,而无需手动切换轨迹


编辑:您确定通知是针对当前项目的吗?或者你是否有一个观察者,观察某个以前玩过的东西,因为某种原因被触发?

是的,我试过了,但由于某些原因,在我的情况下,这是不可接受的。在调试器中,我可以看到通知实际上是从当前播放项发送的。每次更改轨迹时,我都会删除并添加此观察者。您是否发现了此问题?