Tag video by createelement

Asked

Viewed 56 times

0

I’m creating a full page by the Document.createelement() method, only I’m facing a problem creating a video tag. It creates the element but does not play the video, I wonder if the video tag works with the createelement.

    var table = document.createElement("TABLE");
    table.setAttribute("align","center");
    var trplay = document.createElement("TR");
    var tdplay = document.createElement("TD");
    var player = document.createElement("VIDEO");
    player.setAttribute("width","502");
    player.setAttribute("height","360");
    player.setAttribute("id","Video1");
    var source = document.createElement("SOURCE");
    source.setAttribute("scr","video1.webm");
    source.setAttribute("type","video/webm");

it creates the following code:

<table align="center">
 <tr>
  <td>
   <video width="502" height="360" id="Video1">
    <source scr="video1.webm" type="video/webm">
   </video>
  </td>
 </tr>
</table>

1 answer

1


Try creating the widget as follows:

var player = document.createElement('video');
player.src = 'video1.webm';
player.autoPlay = true;

So it will set playback automatically. Your problem may also be linked to the video format, which you can check so:

if (player.canPlayType('video/webm').length > 0) {
    /* Aqui o formato é suportado */
}

I believe this will work.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.