How to make audio autoplay on chrome

后端 未结 17 1620
南旧
南旧 2020-11-22 08:42

audio autoplay working in Mozilla, Microsoft edge and old google chrome as well but not in new google chrome. they have blocked the autoplay. is there any way to make it au

17条回答
  •  失恋的感觉
    2020-11-22 09:12

    At least you can use this:

    document.addEventListener('click', musicPlay);
    function musicPlay() {
        document.getElementById('ID').play();
        document.removeEventListener('click', musicPlay);
    }
    

    The music starts when the user clicks anywhere at the page.

    It removes also instantly the EventListener, so if you use the audio controls the user can mute or pause it and the music doesn't start again when he clicks somewhere else..

提交回复
热议问题