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.
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.
The autoplay attribute is a boolean attribute. When present, the audio will automatically start playing as soon as it can do so without stopping.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With