Detect if HTML5 Video element is playing

user1076821 picture user1076821 · Dec 22, 2011 · Viewed 162.5k times · Source

I've looked through a couple of questions to find out if an HTML5 element is playing, but can't find the answer. I've looked at the W3 documentation and it has an event named "playing" but I can't seem to get it to work.

This is my current code:

var stream = document.getElementsByTagName('video');

function pauseStream() {
  if (stream.playing) {
    for (var i = 0; i < stream.length; i++) {
      stream[i].pause();
      $("body > header").addClass("paused_note");
      $(".paused_note").text("Stream Paused");
      $('.paused_note').css("opacity", "1");
    }
  }
}

Answer

Samuel Cole picture Samuel Cole · Oct 9, 2012

It seems to me like you could just check for !stream.paused.