未调用AVPlayerItemDidPlayToEndTimeNotification [英] AVPlayerItemDidPlayToEndTimeNotification not called

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

问题描述

我在屏幕上有一个必须无限循环播放的视频.

I have a video on a screen that must be played with an infinity loop.

所以我写了:

self.player = [AVPlayer playerWithPlayerItem:avItem];

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(playerItemDidReachEnd:)
                                             name:AVPlayerItemDidPlayToEndTimeNotification
                                           object:[_player currentItem]];

[_player play];

我的备用方法是:

- (void)playerItemDidReachEnd:(NSNotification *)notification {
    [_player.currentItem seekToTime:kCMTimeZero];
    [_player play];
}

效果很好,但有时似乎没有调用我的后备广告.该视频在结尾处冻结,并且不再播放.它是随机发生的...

It works well but sometimes it seems that my fallback is not called. The video is freezing at the end and never played again. It's happening randomly ...

你有个主意吗?

推荐答案

[_player currentItem]null,因为您尚未开始玩游戏.我建议要么明确地添加AVPlayerItem(理想情况下),要么在开始播放后注册到通知中(倒数第二行).

[_player currentItem] is null, since you haven't started playing yet. I would suggest either to explicitly add the AVPlayerItem (ideally) or register to notifications after starting the playback (reverse the 2 last lines).

我还没有尝试第二种解决方案,因此,如果需要一些时间来开始播放,它可能不起作用.如果是这种情况,我建议将NSTimer设置为稍后触发第二秒,然后注册.

I have not tried the 2-nd solution, so it might not work, if it takes some time to start the playback. If that is the case, I suggest setting an NSTimer to trigger a second later and then register.

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

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