AliJP
AliJP

Reputation: 678

Reduce html5 audio tag buffer

I use html5 audio tag to play an audio live stream. everything's ok but I have a 10 seconds delay for buffering audio tag data.

I searched the web and find out autoplay attribute fire play after the audio tag buffered data enough.

So I removed this attribute and tried to play it programmatically with the code below:

audio.addEventListener('loadstart', function (e) {
                    audio.play();
});

But the audio not playing after audio.play() calls and I think it's because of not enough buffered data.

What should I do to reduce delay time for live playing?

Upvotes: 3

Views: 1351

Answers (1)

Brad
Brad

Reputation: 163240

You can't control the buffering of an audio tag. The buffering and delay is dependent on implementation, and is more complicated than a single setting as there are buffers along every step of the chain.

If latency matters for your application, I suggest implementing a WebRTC client which is built for low-latency. If you need even more control, you can receive audio data over web sockets and playback with the Web Audio API, but this requires you to manage the buffering yourself and makes codecs tricky, for likely no improvement over WebRTC.

Upvotes: 1

Related Questions