Video autoplay problem

3

I added a video shortly when I started the site and I wanted it to be in autoplay.

I know that if I put the page in html5 it would perform as well as I did the test. But as it is inside this box and using js, it does not start.

The script code in js that I'm using is this:

<script>
$(document).ready(function(){
   $(".iframe").colorbox({iframe:true, width:"80%", height:"80%"});
   $.colorbox({href:"comunicado.php"});
   $('#video_player').prop('autoplay', true);
});
</script>

And in the video in html I have it like this:

<video width="99%" height="500" controls="controls" autoplay="autoplay">
   <source id="video_player" src="comercial.mp4" type="video/mp4">
</video>

I have tried in several ways, but since I am not an expert I do not know what is happening. I would love your help!

    
asked by anonymous 20.12.2016 / 12:35

2 answers

0

HTML is just autoplay .

<video width="99%" height="500" id="video" controls autoplay>
    <source id="video_player" src="comercial.mp4" type="video/mp4">
</video>

And you do not need it:

$('#video_player').prop('autoplay', true);

Do so in your JavaScript code:

document.getElementById('video').play();

And in the tag video put id="video" .

    
20.12.2016 / 12:42
0
<video width="400" controls id='meu_video'>
      <source src="mov_bbb.mp4" type="video/mp4">
      <source src="mov_bbb.ogg" type="video/ogg">
      Your browser does not support HTML5 video.
</video>
<script>
    $('document').ready(function(){
        var video = document.getElementById("meu_video"); 
        video.play();
    });
</script>

See if it works. I did the tests here and it worked.

    
21.03.2017 / 22:37