I inserted the audio in html. But the audio gets started before the entire page loads. I want the audio to be played after the entire page gets loaded.
<audio src="bg.mp3" autoplay="autoplay" loop="loop"></audio>
Can anyone help me in this.
The HTML <audio> autoplay attribute is used to specify that the audio should automatically start playing as soon as it is loaded. It is a Boolean attribute.
Just add an invisible iframe with an . mp3 as its source and allow="autoplay" before the audio element. As a result, the browser is tricked into starting any subsequent audio file.
The audio tag allows you to embed audio content in your HTML pages. By default the browser does not show any controls for this element. Which means the audio will play only if set to autoplay (more on this later) and the user can't see how to stop it, or control the volume or move through the track.
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.
You're going to need JavaScript for that. Remove the autoplay
attribute:
<audio id="my_audio" src="bg.mp3" loop="loop"></audio>
and add a script like this:
window.onload = function() {
document.getElementById("my_audio").play();
}
Or if you use jQuery:
$(document).ready(function() {
$("#my_audio").get(0).play();
});
Just Copy and Paste this Code in Body section of your HTML Code.
<audio autoplay>
<source src="song.mp3" type="audio/mpeg">
</audio>
and make sure that your audio file should be in same folder.
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