Hanfei Sun
Hanfei Sun

Reputation: 47061

The `success` and `ready` event for HTML5 `<audio>` tag?

Here is my code (coffeescript):

toVoice = new Audio("myVoice.mp3")
toVoice.addEventListener("ended", ->console.log("ended"))
toVoice.addEventListener("error", ->console.log("error"))
toVoice.addEventListener("success", ->console.log("success"))
toVoice.addEventListener("ready", ->console.log("ready"))

I want to show a message when:

  1. the remote audio file is downloadable
  2. the audio file is playable

I found the ended and error eventListener works well, but the success and ready eventListener doesn't work.

I tried to find a MDN documentation about all the available events for Audio tag/object but I didn't find one..

Does anyone have ideas about how to register a callback to detect whether an audio is valid and playable?

Upvotes: 2

Views: 2285

Answers (1)

Arun P Johny
Arun P Johny

Reputation: 388316

There are no success or ready events for media element

I think you can try loadstart and loadeddata

toVoice = new Audio("myVoice.mp3")
toVoice.addEventListener("ended", ->console.log("ended"))
toVoice.addEventListener("error", ->console.log("error"))
toVoice.addEventListener("canplay", ->console.log("canplay"))
toVoice.addEventListener("loadeddata", ->console.log("loadeddata"))

Upvotes: 5

Related Questions