Video tag by createelement

0

I'm creating a whole page using the Document.createElement () method, but I'm having a problem creating a video tag. It creates the element but does not play the video, I would like to know if the video tag works with 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>
    
asked by anonymous 09.02.2017 / 11:14

1 answer

1

Attempts to create the element as follows:

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

This will set the playback automatically. Your problem may also be tied to the video format, which you can check as follows:

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

I believe that this will work.

    
09.02.2017 / 11:30