I have to play beep sound on response. I have written code for this but it is not working when I manually refresh the browser page. It is showing error “DOMException: play() failed because the user didn’t interact with the document first”.
I’m calling $scope.sound function on ng-init on a template. It works in another browser like IE, Microsoft EDGE, etc. but not work on Google Chrome. Anybody from the community, please help me with this issue.
$scope.sound = function () {
if ($scope.totalQueueList) {
var audio = new Audio();
audio.src = 'rest/assets/images/beep.mp3';
// when the sound has been loaded, execute your code
audio.oncanplaythrough = (event) => {
var playedPromise = audio.play();
if (playedPromise) {
playedPromise.catch((e) => {
console.log(e)
if (e.name === 'NotAllowedError' || e.name === 'NotSupportedError') {
console.log(e.name);
}
}).then(() => {
});
}
}
}
}