问题描述
如何从 TVMLKit JS 播放器对象获取比特率信息? 在苹果文档(https://developer.apple.com/documentation/tvmljs/player)中,我无法识别返回此特定信息的任何属性/方法。是否可以获取此信息?
解决方法
似乎没有任何方法可以从 JS 读取播放器项目的访问日志。至少我也找不到。
但是,如果您有权访问本机代码,作为一种解决方法,您可以监听 AVPlayerItemNewAccessLogEntry
通知。
不是完美的解决方案,但对于您的用例来说可能已经足够了。
// Add observer somewhere.
NotificationCenter.default.addObserver(self,selector: #selector(accessLog(notification:)),name: .AVPlayerItemNewAccessLogEntry,object: nil)
@objc func accessLog(notification: Notification) {
guard let playerItem = notification.object as? AVPlayerItem,let accessLogEvent = playerItem.accessLog()?.events.last
else { return }
_ = accessLogEvent.observedBitrate
}