0

I need to Use audio sound on new requests based on business logic. when I call "playAudio()" this function in Page Load Means NgOninit It's not working. it giving me the below error.

prescan-orderlist.component.ts:116 Uncaught (in promise) DOMException: play() failed because the user didn't interact with the document first.

I search for that but based on crome new policy they have restricted.

Please help me if you have any idea to achieve this.

public playAudio() {
    let audio = new Audio();
    audio.src = "../assets/images/beep.wav";
    audio.load();
    audio.play();

  }
Mitul Patel
  • 66
  • 1
  • 1
  • 11
  • Does this answer your question? [How to handle "Uncaught (in promise) DOMException: play() failed because the user didn't interact with the document first." on Desktop with Chrome 66?](https://stackoverflow.com/questions/49930680/how-to-handle-uncaught-in-promise-domexception-play-failed-because-the-use) – Harun Yilmaz Dec 12 '19 at 12:59

1 Answers1

0

Starting with Chrome 66, pages can't play media automatically unless they are muted or the user starts the playback.

A page can start autoplay, but only with audio muted. You could set the muted property like this:

public playAudio() {
    let audio = new Audio();
    audio.src = "../assets/images/beep.wav";
    audio.muted = true;
    audio.load();
    audio.play();
}

However, since you are trying to play an audio file, not video, this will be pointless.

ulmas
  • 2,203
  • 16
  • 22