Bitrate in TVMLKit JS media player

110 Views Asked by At

How to get bit rate information from the TVMLKit JS player object? In apple documentation(https://developer.apple.com/documentation/tvmljs/player), I am not able to identify any attribute/method that returns this particular information. Is this possible to get this information?

1

There are 1 best solutions below

0
anders On

Doesn't seem like there is any way to read the player item's access log from JS. At least none that I have been able to find either.

However, if you have access to the native code, as a workaround, you can listen for the AVPlayerItemNewAccessLogEntry notification.

Not the perfect solution, but perhaps it's enough for your use-case.

// 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
}