4

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

Inspired by the above thread, 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 variable bitRate is always zero when checked inside a timer.

In fact [logEvents count] is also always zero.

Could you please tell me what is wrong with the technique ?

Thanks a lot.

Community
  • 1
  • 1
Protonization
  • 41
  • 1
  • 3

2 Answers2

4

In addition to Ooops's suggestion, it might be wise to register for the AVPlayerItemNewAccessLogEntryNotification notification to check for the bitrate.

Since the access log array isn't KVO compliant, using the notification would allow you to not use a timer to check for updates and you wouldn't have to worry about waiting for the player item to be ready. If the events are being fired too frequently, you could choose to ignore some.

Mackworth
  • 71
  • 5
0

Nothing's wrong with the method. Check if your playerItem is actually loaded. The accessLog is nil until the playerItem is 'access'ed. Try to get the accessLogs after your player becomes AVPlayerStatusReadyToPlay and you'll get the log.

Ooops
  • 269
  • 2
  • 12