How to handle Uncaught (in promise) DOMException: The play() request was interrupted by a call to pause()

asp.net, javascript, wav

Solution

For Chrome they changed autoplay policy, so you can read about here:

var promise = document.querySelector('audio').play();

if (promise !== undefined) {
    promise.then(_ => {
        // Autoplay started!
    }).catch(error => {
        // Autoplay was prevented.
        // Show a "Play" button so that user can start playback.
    });
}

Problem

Below is my code in aspx page to allow playing audio's of wav format in the browser but with my current code I am unable to play wav audios in Chrome browser but it works in Firefox. How can I handle this exception? ``` <script> window.onload = function () { document.getElementById("audio").play(); } window.addEventListener("load", function () { document.getElementById("audio").play(); }); </script> <body> <audio id='audio' controls autoplay> <source src="Sounds/DPM317.wav" type="audio/wav" /> Your browser does not support the audio element. </audio> </body> ```

Original source