简体   繁体   中英

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. We have tested audio streaming protocols like HTTP & HLS and have observed a minimum of 3 seconds latency to play. Does AVPlayer require an input buffer of a minimum of 3 seconds on the device before starting the playback?

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. 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. 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.

Other APIs and protocols can potentially add large amounts of overhead and buffering latency.

You can just observe playerItem.loadedTimeRanges an play pause AVPlayer manually if buffer (aka loadedTimeRanges) enough for you latency conditions

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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