I'm playing an MP3 using the <audio>
tag in HTML5.
<audio controls="controls" autoplay="autoplay">
<source src="song.mp3" type="audio/mp3" />
</audio>
This works fine, but I am wondering how I can put a delay in before the song starts to autoplay? I know there's not a delay
attribute, but I'm thinking it could be accomplished via javascript?
Repairing glitches and delays in Windows 10 audio playback is actually quite simple once the problem has been diagnosed. To begin, right-click on the audio icon in the taskbar and select “Playback Devices”: Double-click on your primary audio device to bring up the speaker/headphones properties dialog, and navigate to the “Advanced” tab:
This is the main function to play audio after 8 seconds. To check if your function is working or not you can use console log. This line will add a console message when the audio starts playing. Just put your audio path in the src attribute. loop will play the audio file repeatedly.
A common problem that faces some users of Windows 10 is delays in the audio output. This guide features a number of common issues faced when playing audio in Windows 10 and a possible solution. This problem can occur with different hardware, but many reports of these issues have been reported with Realtek audio chips.
This line will add a console message when the audio starts playing. Just put your audio path in the src attribute. loop will play the audio file repeatedly.
Try this, really simple but you should move the JS outside the markup...
<audio controls="controls" onloadeddata="var audioPlayer = this; setTimeout(function() { audioPlayer.play(); }, 8000)">
<source src="Kalimba.mp3" type="audio/mp3" />
</audio>
Javascript only method:
var sound = document.createElement('audio')
sound.id = 'audio'
sound.controls = 'controls'
sound.src = 'http://a.tumblr.com/tumblr_leltkjNwWL1qf32t9o1.mp3'
sound.type = 'audio/mp3'
document.body.appendChild(sound)
function playAudio() {
document.getElementById('audio').play();
}
setTimeout("playAudio()", 3000);
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