Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does the html5 <audio> tag load the audio from the server before activating?

Tags:

html

jquery

I didn't quite know how to phrase the question, but here is the code...

<audio class='foo' preload='none'>
    <source src='./path.mp3'>
</audio>

I then have some jQuery that plays the clip when clicked with this function...

function play(parent, child) {
    $(parent).find(child).find('.bar').click(function() {
        $('.word-audio')[0].play();
    });
}

My question is whether this transfers the audio file when the html loads or when the button is clicked? I would like to only be loading data when buttons are clicked since my page could possibly have hundreds of these.

like image 985
Joff Avatar asked Oct 14 '15 05:10

Joff


People also ask

How does an HTML audio tag works?

HTML Audio - How It WorksThe <source> element allows you to specify alternative audio files which the browser may choose from. The browser will use the first recognized format. The text between the <audio> and </audio> tags will only be displayed in browsers that do not support the <audio> element.

How do I make audio start automatically in HTML?

The autoplay attribute is a boolean attribute. When present, the audio will automatically start playing as soon as it can do so without stopping.

How do I preload audio in HTML?

We use preload=”auto” attribute to preload the audio file. The HTML Audio Preload Attribute is used to specify how the author thinks the audio should be loaded when the page loads. The audio preload attribute allows the author to indicate to the browser how the user experience of a website should be implemented.

Is audio introduced in HTML5?

Since the release of HTML5, audios can be added to webpages using the “audio” tag. Previously, audios could be only played on web pages using web plugins like Flash. The “audio” tag is an inline element that is used to embed sound files into a web page.


2 Answers

I think this description will clear your douts...

<audio preload="auto|metadata|none">

Attribute Values

auto : The author thinks that the browser should load the entire audio file when the page loads
metadata : The author thinks that the browser should load only metadata when the page loads
none : The author thinks that the browser should NOT load the audio file when the page loads.

like image 71
Allen Avatar answered Sep 22 '22 04:09

Allen


Your code is not preloading the audio. This behavior is because you are using the preload="none" attribute. See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio. This behavior is part of the W3 standard, not just Firefox; see https://www.w3.org/wiki/HTML/Elements/audio.

like image 36
Bennett Brown Avatar answered Sep 25 '22 04:09

Bennett Brown