HTML DOM Video poster Property


The HTML DOM Video poster property returns/sets a string corresponding to the url of an image shown until the video is played or network state is equal to ‘2’.

Syntax

Following is the syntax −

Returning string value

mediaObject.poster

Setting poster to a URLString

mediaObject.poster = URLString

Let us see an example of HTML DOM Video poster property −

Example

Live Demo

<!DOCTYPE html>
<html>
<head>
<title>HTML DOM Video poster</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-poster</legend>
         <video id="demo" width="320" controls><source    src="http://www.tutorialspoint.com/html5/foo.mp4" poster='' type="video/mp4"></video><br>
         <input type="button" onclick="getTrackDetails()" value="Get Poster URL">
         <div id="divDisplay"></div>
      </fieldset>
   </form>
   <script>
      var divDisplay = document.getElementById("divDisplay");
      var demo = document.getElementById("demo");
      function getTrackDetails() {
         if(demo.poster === '')
            divDisplay.textContent = 'No Poster, 1st frame of video used as poster';
         else
            divDisplay.textContent = 'Poster URL: '+demo.poster;
      }
   </script>
</body>
</html>

Output

Before clicking ‘Get Poster URL’ button −

After clicking ‘Get Poster URL’ button −

Updated on: 18-Feb-2021

49 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements