在我的应用程序中,我使用 AVPlayer 通过 HLS 协议读取一些流(m3u8 文件)。我需要知道在流会话期间,客户端切换比特率多少次.
我们假设客户端的带宽正在增加。因此客户端将切换到更高比特率的段。
AVPlayer能检测到这个开关吗?
Thanks.
我最近也遇到了类似的问题。该解决方案感觉有点老套,但据我所知它有效。首先,我为新的访问日志通知设置一个观察者:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleAVPlayerAccess:)
name:AVPlayerItemNewAccessLogEntryNotification
object:nil];
哪个调用了这个函数。它可能可以优化,但基本思想如下:
- (void)handleAVPlayerAccess:(NSNotification *)notif {
AVPlayerItemAccessLog *accessLog = [((AVPlayerItem *)notif.object) accessLog];
AVPlayerItemAccessLogEvent *lastEvent = accessLog.events.lastObject;
float lastEventNumber = lastEvent.indicatedBitrate;
if (lastEventNumber != self.lastBitRate) {
//Here is where you can increment a variable to keep track of the number of times you switch your bit rate.
NSLog(@"Switch indicatedBitrate from: %f to: %f", self.lastBitRate, lastEventNumber);
self.lastBitRate = lastEventNumber;
}
}
每次访问日志中有新条目时,它都会检查最近条目(播放器项目的访问日志中的最后一个对象)中最后指示的比特率。它将指示的比特率与存储上次更改的比特率的属性进行比较。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)