HTML DOM Video playbackRate Property

HTMLWeb DevelopmentFront End Technology

The HTML DOM Video playbackRate property returns/sets a number corrosponding to current playback rate of media.

Syntax

Following is the syntax −

Returning playbackRate as a number

mediaObject.playbackRate

Setting playbackRate to a number

mediaObject.playbackRate = number

NOTENumber has a max value of ‘16’ and if ‘0.0’ video is still.

Let us see an example of Video playbackRate property −

Example

<!DOCTYPE html>
<html>
<head>
<title>HTML DOM Video playbackRate</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-playbackRate</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="getTrackDetails(1)" value="Slow (<<)">
         <input type="button" onclick="getTrackDetails(2)" value="Fast (>>)">
         <div id="divDisplay"></div>
      </fieldset>
   </form>
<script>
   var divDisplay = document.getElementById("divDisplay");
   var demo = document.getElementById("demo");
   function getTrackDetails(val) {
      if(val === 1){
         demo.playbackRate -= 0.5;
         divDisplay.textContent = 'Default Playback Set: '+demo.playbackRate;
      }
      else{
         demo.playbackRate += 0.5;
         divDisplay.textContent = 'Default Playback Set: '+demo.playbackRate;
      }
   }
</script>
</body>
</html>

Output

Clicking ‘Fast (>>)’ button 2 times −

Now, click ‘Slow (<<)’ button once −

raja
Published on 31-Oct-2019 10:23:25
Advertisements