未使用iOS 8调用AVPlayerItemDidPlayToEndTimeNotification [英] AVPlayerItemDidPlayToEndTimeNotification not being called with iOS 8

查看:813
本文介绍了未使用iOS 8调用AVPlayerItemDidPlayToEndTimeNotification的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

AVPlayerItem *currentItem = self.player.currentItem;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playerItemDidReachEnd:) name:AVPlayerItemDidPlayToEndTimeNotification object:currentItem];

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

I have the above notification setup. It is being called fantastically when I run tests with iOS 7, however, it's never being called with I run my application with iOS 8.

推荐答案

通过向速率密钥路径注册观察者来解决此问题。

It is resolved by registering an observer to the rate keypath.

[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
    }
}

这篇关于未使用iOS 8调用AVPlayerItemDidPlayToEndTimeNotification的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆