当前位置 : 主页 > 手机开发 > ios >

ios8 – 未使用iOS 8调用AVPlayerItemDidPlayToEndTimeNotification

来源:互联网 收集:自由互联 发布时间:2021-06-11
AVPlayerItem *currentItem = self.player.currentItem;[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playerItemDidReachEnd:) name:AVPlayerItemDidPlayToEndTimeNotification object:currentItem]; 我有上面的通知设置
AVPlayerItem *currentItem = self.player.currentItem;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playerItemDidReachEnd:) name:AVPlayerItemDidPlayToEndTimeNotification object:currentItem];

我有上面的通知设置.当我使用iOS 7运行测试时,它被称为奇妙的,但是,我从未使用iOS 8运行我的应用程序.

通过将一个观察者注册到速率密钥路径来解决它.

[self.player addObserver:self forKeyPath:@"rate" options:0 context:nil];

- (void)observeValueForKeyPath:(NSString*)keyPath ofObject:(id)object change:(NSDictionary*)change context:(void*)context {
if (self.player.rate == 0.0) {
    CMTime time = self.player.currentTime;
    if (time >= duration) {
        //song reached end
    }
}
网友评论