在网页中设置自动播放音频
<script type="text/javascript">
let sound1 = "{{MEDIA_URL}}/media/music/今天你要嫁给我_陶喆,蔡依林.mp3";
let sound2 = "{{MEDIA_URL}}/media/music/咱们结婚吧_齐晨.mp3";
let sound3 = "{{MEDIA_URL}}/media/music/甜甜的_周杰伦.mp3";
let sound4 = "{{MEDIA_URL}}/media/music/苏打绿_小情歌.mp3";
let x = Math.round(Math.random() * 10);
if (x < 3) {
x = sound1;
} else if (x < 5) {
x = sound2;
} else if (x < 8) {
x = sound3;
} else if (x <= 10) {
x = sound4;
}
if (navigator.appName == "Microsoft Internet Explorer") {
document.write('<bgsound src=' + '"' + x + '"' + ' loop="infinite">');
} else {
{#document.write('<embed src=' + '"' + x + '"' + 'hidden="true" autostart="true" loop="true">');#}
document.getElementById("bgm").innerHTML = ('<audio controls="controls" autoplay="autoplay">' +
' <source src=' + '"' + x + '" type="audio/mpeg">' +
'Your browser does not support the audio element.' +'</audio>');
}
</script>