-1

I'm using JS Audio class to play a file:

var audio = new Audio('hello.mp3');
audio.play();

Is there a way to use an event to detect the file play has ended?

Koby Douek
  • 16,156
  • 19
  • 74
  • 103
  • It's the same thing. Same solutions apply. – j08691 Dec 04 '19 at 14:33
  • @j08691 So? Does that mean it's a duplicate? You made a mistake you should reopen. This questions does not exist in SO. – Koby Douek Dec 04 '19 at 14:36
  • I wasn't the only one to VTC and yes, it's still a dupe – j08691 Dec 04 '19 at 14:47
  • Two wrongs doesn't make it right. It's not a duplicate because the question does not exist. simple as that. Is closing a question as a duplicate valid because the answer is the same? Own up to your mistake. This question was not supposed to be closed. – Koby Douek Dec 04 '19 at 14:57

1 Answers1

1

Try this:

var audio = new Audio('hello.mp3');
audio.play();
audio.onended = function() {
  console.log("The audio has ended");
};

Here is the doc

Daniyal Lukmanov
  • 1,149
  • 10
  • 21