小编Tan*_*nya的帖子

当项目未完成播放时,将发布AVPlayerItemDidPlayToEndTimeNotification

我正在使用AVPlayer播放来自网络的曲目.在我的播放列表中总有几首曲目.因此,为了定义当前轨道到达结束时将采取的操作,我使用KVO机制并注册发布的AVPlayerItemDidPlayToEndTimeNotification的观察者.

    if (_player.currentItem.status == AVPlayerItemStatusReadyToPlay)
    {
       [self play];
       [NSNotificationCenter defaultCenter] addObserver:self selector:@selector(itemReachedEnd:) name:AVPlayerItemDidPlayToEndTimeNotification object:_player.currentItem];
    }
Run Code Online (Sandbox Code Playgroud)

发布通知时,将调用itemReachedEnd方法:

- (void) itemReachedEnd:(NSNotification *) notification
{
dispatch_async(dispatch_get_main_queue(), ^{
    //switching to the next track
}
Run Code Online (Sandbox Code Playgroud)

事情是,有时这个方法在项目尚未完成播放时被调用,并且我已经在当前音轨播放结束之前切换了当前音轨.我不明白为什么会这样.

请告诉我,我做错了什么?也许我需要在跟踪切换之前考虑其他一些AVPlayerItem属性?

更新:我已经探索过当前轨道的当前位置不等于当前轨道持续时间.那么为什么玩家认为当前的项目已经完成了?

objective-c ios avplayer

6
推荐指数
1
解决办法
767
查看次数

标签 统计

avplayer ×1

ios ×1

objective-c ×1