Determining AVPlayer Data Rate

I am playing a live audio stream using AVPlayer and AVPlayerItem and trying to determine the current bit rate in the stream. I searched the net and found this help: MPMovieController baud rate determination

Inspired by the stream above, I tried to compute it using the following code:

 NSArray *logEvents=playerItem.accessLog.events; AVPlayerItemAccessLogEvent *event = (AVPlayerItemAccessLogEvent *)[logEvents lastObject]; double bitRate=event.observedBitrate; 

But the bitRate variable bitRate always zero when it is checked inside the timer.

In fact, [logEvents count] also always zero.

Could you tell me what is wrong with the technique?

Thank you very much.

+4
source share
2 answers

In addition to the Ooops offer, it would be wise to register to notify AVPlayerItemNewAccessLogEntryNotification to check the bitrate.

Since the access log array does not meet the KVO requirements, using this notification will allow you not to use a timer to check for updates, and you donโ€™t have to worry about waiting until the playerโ€™s position is ready. If events are fired too often, you can ignore some of them.

+4
source

Nothing wrong with the method. Check if your playerItem is really loaded. AccessLog is zero until playerItem accesses. Try to get accessLogs after your player becomes AVPlayerStatusReadyToPlay and you get a log.

0
source

All Articles