Currently in the project, I hope to be able to play background music as soon as you enter the webpage, but chrome seems to have banned this!
Find a way to crack on the Internet, the reference website is as follows:
http://www.nooong.com/docs /chrome_video_autoplay.htm
But I tried to use the above method by myself, the effect is still useless.
I would like to ask you to help me to see if the spelling is wrong, or is it useless at all?
Maybe you have had similar needs, I hope you can share with me, I will be very grateful for your warm help, thank you again Everyone watch my question.
let trigger = document.querySelector('.trigger');
let autoplay = document.querySelector('.autoplay');
trigger.onload = function(){
autoplay.src = 'demo.mp3';
autoplay.oncanplay = function(){
autoplay.play();
};
};
<!-- background music to play -->
<audio autoplay="autoplay" controls="controls" loop ="loop" preload ="auto" class="autoplay">
<source src="demo.mp3" />
</audio>
<!-- First trigger the audio in the iframe, put an empty music file in it -->
<iframe allow="autoplay" style="display:none" class="trigger" src="demo.mp3"></iframe>