简体   繁体   English

需要在 iOS (Swift) 中无延迟地通过 Internet 播放 mp3 音频

[英]Need to play a mp3 audio over the internet without latency in iOS (Swift)

We are trying to achieve low latency audio streaming(only encoded audio data present, no video data) using AVPlayer.我们正在尝试使用 AVPlayer 实现低延迟音频流(仅存在编码的音频数据,没有视频数据)。 We have tested audio streaming protocols like HTTP & HLS and have observed a minimum of 3 seconds latency to play.我们测试了 HTTP 和 HLS 等音频流协议,并观察到至少 3 秒的播放延迟。 Does AVPlayer require an input buffer of a minimum of 3 seconds on the device before starting the playback?在开始播放之前,AVPlayer 是否需要设备上至少 3 秒的输入缓冲区?

Does latency reduction have any correlation with the quality of audio playback?延迟减少是否与音频播放质量相关?

Can we reduce this latency?我们可以减少这种延迟吗? If yes, are there any suggestions or recommended practices?如果是,是否有任何建议或推荐做法?

Latency can be minimized by using Audio Units, as Audio Units can request to be configured with very short audio buffers, typically 20 mS down to 5 mS, or even less on some Apple devices.使用音频单元可以最大限度地减少延迟,因为音频单元可以请求配置非常短的音频缓冲区,通常为 20 毫秒到 5 毫秒,在某些 Apple 设备上甚至更低。 UDP with MTU size packets can be used to stream data over the network, where your network buffering and traffic interference may be the dominating factor in added latency.具有 MTU 大小数据包的 UDP 可用于网络上的 stream 数据,其中您的网络缓冲和流量干扰可能是增加延迟的主要因素。 You will likely have to add some amount of latency (circular ring buffer fill level) to account for worse case network timing jitter.您可能必须添加一些延迟(循环环形缓冲区填充级别)来解决更糟糕的情况下的网络定时抖动。 Then, for mp3 compressed audio, add on the minimum mp3 block size and how long your chosen mp3 decoder takes.然后,对于 mp3 压缩音频,添加最小 mp3 块大小和您选择的 mp3 解码器需要多长时间。

Other APIs and protocols can potentially add large amounts of overhead and buffering latency.其他 API 和协议可能会增加大量开销和缓冲延迟。

You can just observe playerItem.loadedTimeRanges an play pause AVPlayer manually if buffer (aka loadedTimeRanges) enough for you latency conditions如果缓冲区(又名loadedTimeRanges)足以满足您的延迟条件,您可以手动观察playerItem.loadedTimeRanges播放暂停 AVPlayer

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

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