ios – 处理AVPlayer停顿

ios – 处理AVPlayer停顿,第1张

概述我试图抓住AVPlayer无法继续播放的时刻,以防没有更多媒体可用(网络太慢,信号丢失等).正如文档和不同示例中所述,我正在使用KVO来检测: item = [[AVPlayerItem alloc] initWithURL:audioURL];player = [AVPlayer playerWithPlayerItem:item];[[NSNotificationCenter defaul 我试图抓住AVPlayer无法继续播放的时刻,以防没有更多媒体可用(网络太慢,信号丢失等).正如文档和不同示例中所述,我正在使用KVO来检测:
item = [[AVPlayerItem alloc] initWithURL:audioURL];player = [AVPlayer playerWithPlayerItem:item];[[NSNotificationCenter defaultCenter] addobserver:self selector:@selector(onItemNotification:) name:AVPlayerItemPlaybackStallednotification object:item];[item addobserver:self forKeyPath:@"playbackBufferEmpty" options:NSkeyvalueObservingOptionNew context:nil];[item addobserver:self forKeyPath:@"playbacklikelyToKeepUp" options:NSkeyvalueObservingOptionNew context:nil];...- (voID) onItemNotification:(NSNotification*)not{    NSLog(@"Item notification: %@",not.name);}...- (voID) observeValueForKeyPath:(Nsstring*)keyPath ofObject:(ID)object change:(NSDictionary*)change context:(voID*)context{    NSLog(@"Observe keyPath %@",keyPath);}

我正在开始播放并在此之后关闭WiFi.不幸的是,’playbackBufferEmpty’和’AVPlayerItemPlaybackStallednotification’都没有出现.在播放停止的那一刻,我只收到一个AVPlayerItemTimeJumpednotification,这就是全部.
但是,当我收到这些通知时,至少有2次.但我无法弄清楚每次播放停止时如何获取它们.
难道我做错了什么?

解决方法 首先尝试断开互联网与路由器的连接,然后您将获得playbackBufferEmpty通知.
要处理网络切换,您需要实现 Reachability 总结

以上是内存溢出为你收集整理的ios – 处理AVPlayer停顿全部内容,希望文章能够帮你解决ios – 处理AVPlayer停顿所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1100055.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存