ios – 检测AvPlayer切换比特率的时间

在我的应用程序中,我使用AVPlayer读取一些带有HLS协议的流(m3u8文件).我需要知道在流式传输会话期间,客户端切换比特率的次数.

我们假设客户端的带宽正在增加.因此客户端将切换到更高的比特率段.
AVPlayer可以检测到此开关吗?

谢谢.

解决方法

我最近遇到过类似的问题.解决方案感觉有点hacky,但它在我看到的情况下起作用.首先,我为新的Access Log通知设置了一个观察者:
[[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;
    }
}

每次访问日志都有新条目时,它会检查最近一个条目的最后指示比特率(播放器项目的访问日志中的lastObject).它将此指示的比特率与存储来自最后一次更改的比特率的属性进行比较.

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...