【问题标题】:AVPlayerItemDidPlayToEndTimeNotification is posted when the item did not finish playingAVPlayerItemDidPlayToEndTimeNotification 在项目未完成播放时发布
【发布时间】:2014-06-21 02:17:04
【问题描述】:

我正在使用 AVPlayer 播放来自网络的曲目。在我的播放列表中,总是有几首曲目。 因此,为了定义当前曲目到达终点时将采取的操作,我使用 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:我探索了当前曲目的当前位置不等于当前曲目时长。那为什么玩家会认为当前项目已经播放完了呢?

【问题讨论】:

  • 你有没有发现这个问题?

标签: ios objective-c avplayer


【解决方案1】:

不是您问题的真正答案,但您是否查看过AVQueuePlayer?这应该完全符合您的要求,无需手动切换曲目。

编辑:您确定通知是针对当前项目的吗?或者您可能有一个观察者来观察某个之前播放过的项目,该项目由于某种原因而被触发?

【讨论】:

  • 是的,我试过AVQueuePlayer,但由于某些原因,这在我的情况下是不可接受的。在调试器中,我可以看到 Notification 确实是从当前播放项目发送的。每次更改轨道时,我都会删除并添加这个观察者。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-11-19
相关资源
最近更新 更多