简体   繁体   English

通过HTTP流AAC音频时的AVPlayer延迟

[英]AVPlayer delay when streaming AAC audio via HTTP

I'm using AVPlayer to stream an AAC audio from external server via HTTP like this: 我正在使用AVPlayer通过HTTP从外部服务器流式传输AAC音频,如下所示:

AVPlayer *player = [[AVPlayer alloc] initWithURL:[NSURL URLWithString:myStreamURL]];
[player play];

This method works (it indeed plays audio) but not in a way I want it to work. 这种方法有效(它确实可以播放音频),但不是我想要的那样。 The problem is that there is a very long delay (30 seconds) after invoking play method, then I have to wait 30 seconds looking on a spinning "downloading wheel" on status bar, and the audio plays fine but always after this delay, not earlier. 问题是调用播放方法后会有很长的延迟(30秒),然后我必须等待30秒才能在状态栏上看到旋转的“下载轮”,并且音频可以正常播放,但始终在此延迟之后,而不是较早。

I think it actually downloads the audio, and plays it after it instead of streaming it. 我认为它实际上是下载音频,然后播放而不是流式播放。

I haven't figured how to resolve this issue so far, so any help would be appreciated. 到目前为止,我还没有弄清楚如何解决此问题,因此我们将不胜感激。

Thanks in advance. 提前致谢。

It depends on the audio server, but what I do with AVPlayer is to observe player.currentItem.status property by KVO. 它取决于音频服务器,但是我对AVPlayer所做的是通过KVO观察player.currentItem.status属性。 When it becomes AVPlayerItemStatusReadyToPlay , invoke prerollAtRate . 当它变为AVPlayerItemStatusReadyToPlay ,调用prerollAtRate Then start playing within its completion handler. 然后开始在其完成处理程序中播放。

[player prerollAtRate:1.0 completionHandler:^(BOOL finished){
    if (finished) {
        [player play];
    }
}];

Anyway, first it is recommended to observe "status" , "currentItem.status" and "currentItem.loadedTimeRanges" key paths on the AVPlayer instance, and log them when and how they change. 无论如何,首先建议在AVPlayer实例上观察"status""currentItem.status""currentItem.loadedTimeRanges"键路径,并记录它们何时以及如何更改。 You will see which part takes long time. 您将看到哪个部分花费很长时间。

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

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