简体   繁体   English

确定AVPlayer比特率

[英]Determining AVPlayer bit rate

I am playing live audio stream using AVPlayer and AVPlayerItem and trying to determine the current bit rate of the stream. 我正在使用AVPlayerAVPlayerItem播放实时音频流,并尝试确定流的当前比特率。 I searched in the net and found this help : Determening MPMovieController bit-rate 我在网上搜索并找到了这个帮助: 确定MPMovieController的比特率

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. 但是在定时器内部检查时,变量bitRate始终为零。

In fact [logEvents count] is also always zero. 实际上[logEvents count]也总是为零。

Could you please tell me what is wrong with the technique ? 你能告诉我这项技术有什么问题吗?

Thanks a lot. 非常感谢。

In addition to Ooops's suggestion, it might be wise to register for the AVPlayerItemNewAccessLogEntryNotification notification to check for the bitrate. 除了Ooops的建议之外,注册AVPlayerItemNewAccessLogEntryNotification通知以检查比特率可能是明智的。

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. 由于访问日志数组不符合KVO,因此使用该通知将允许您不使用计时器来检查更新,您不必担心等待播放器项目准备就绪。 If the events are being fired too frequently, you could choose to ignore some. 如果过于频繁地触发事件,您可以选择忽略某些事件。

Nothing's wrong with the method. 这个方法没有错。 Check if your playerItem is actually loaded. 检查你的playerItem是否实际加载。 The accessLog is nil until the playerItem is 'access'ed. accessLog是nil,直到playerItem被“访问”。 Try to get the accessLogs after your player becomes AVPlayerStatusReadyToPlay and you'll get the log. 在播放器成为AVPlayerStatusReadyToPlay后尝试获取accessLogs,您将获得日志。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM