Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I force an HTML5 audio element to buffer an entire song?

I'm developing a local server that will stream a user's audio files so they can access them via web browsers using the HTML5 audio object. Since these files are on the user's computer, I expect the files to be buffered completely when they are loaded, but for certain large files, the songs get buffered part of the way, then stop, and resume buffering some time later.

My question is: how can I force the audio object to buffer the entire song at once? Can I do this from javascript, do I have to set an attribute on the audio object, or is there anything else I can do?

like image 392
George Avatar asked Jan 21 '11 21:01

George


People also ask

Which attribute enables automatic buffering of an audio file in HTML5?

autobuffer: If this attribute is used, the audio will begin buffering automtically, even if the playback isn't automatic. controls: This attribute allows the user to control audio playback, volume, seeking and pause or resume playback.

How do you repeat audio in HTML?

This is done by using the loop attribute of the <audio> tag. It is used to restart the audio again and again after loading the web page.

What is the use of preload auto attribute in audio?

The preload attribute specifies if and how the author thinks that the audio file should be loaded when the page loads. The preload attribute allows the author to provide a hint to the browser about what he/she thinks will lead to the best user experience. This attribute may be ignored in some instances.


1 Answers

The solution I found was this:

function load() {
    a.play();
    setTimeout("a.pause()", 10);
}

Play the file and pause it 10ms later, then the browser will buffer the entire song.

like image 72
Ahi Tuna Avatar answered Oct 08 '22 04:10

Ahi Tuna