Javascript DOM HTML Video play() Method

Introduction

A video with play and pause buttons:

Click the buttons to play or pause the video.

View in separate window

<!DOCTYPE html>
<html>
<body>
<video id="myVideo">
  <source id="mp4_src" src="video.mp4" type="video/mp4">
  <source id="ogg_src"  src="video.ogg" type="video/ogg">
  Your browser does not support the video tag.
</video>//from ww w  . j  a v a 2  s .  com
<button onclick="playVid()" type="button">Play Video</button>
<button onclick="pauseVid()" type="button">Pause Video</button>

<script>
var x = document.getElementById("myVideo");
function playVid() {
  x.play();
}

function pauseVid() {
  x.pause();
}
</script>
</body>
</html>

The play() method starts playing the current video.

This method is often used together with the pause() method.




PreviousNext

Related