Search code examples
javascripthtmlcssdom-eventshtml5-audio

<audio> HTML5 element state using Javascript


I was wondering if there was any Javascript method that could help getting information on the state of an audio tag:

  • is the audio playing
  • has it stopped
  • is it muted
  • is it paused

and the sort. I know that we can use play(), pause() and others but not quite sure on how to check in the script that the audio is playing in order to trigger another event/action maybe ?


Solution

  • Yes you can check a number of attributes on the HTML5 media elements, a list of which you can find in the W3C HTML5 Specification itself.

    Under the "playback state" list you can see such attributes as paused, muted, ended etc.