HTML DOM Video play( ) Method


The HTML DOM Video play() is used for playing the current media content and to stopping media use pause().

Syntax

Following is the syntax −

videoObject.play()

Let us see an example of Video play() property −

Example

Live Demo

<!DOCTYPE html>
<html>
<head>
<title>HTML DOM Video play()</title>
<style>
   * {
      padding: 2px;
      margin:5px;
   }
   form {
      width:70%;
      margin: 0 auto;
      text-align: center;
   }
   input[type="button"] {
      border-radius: 10px;
   }
</style></head>
<body>
   <form>
      <fieldset>
         <legend>HTML-DOM-Video-play( )</legend>
         <video id="demo" width="320" controls><source    src="http://www.tutorialspoint.com/html5/foo.mp4" type="video/mp4"></video><br>
         <input type="button" onclick="setControls(1)" value="Play">
         <input type="button" onclick="setControls(2)" value="Pause">
         <div id="divDisplay"></div>
      </fieldset>
   </form>
<script>
   var divDisplay = document.getElementById("divDisplay");
   var demo = document.getElementById("demo");
   function setControls(val) {
      if(val === 1){
         demo.play();
         divDisplay.textContent = 'Video is playing';
      }
      else{
         demo.pause();
         divDisplay.textContent = 'Video is paused';
      }  
   }
</script>
</body>
</html>

Output

Clicking ‘Play’ button −

Clicking ‘Pause’ button −

Updated on: 18-Feb-2021

161 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements