Search code examples
javascriptjqueryhtmlvideoautoplay

How to enable JQuery video autoplay


Just wondering how to get a video to load and autoplay, once another video is finished playing. I'm a bit of a noob, and I'm really

HTML

<div class="videoWrapper">
    <video id="video2" controls>
        <source src="videos/wotebackinupsong.mp4">
        <source src="videos/wotebackinupsong.ogv">
    </video>
</div>

JS

$(document).ready(function() {
    $('#video2').hide(function() {});
    $('#video1').bind('ended', function() {
        $('#video2').show();
    });
});

So far, I've got the 2nd video to hide when the page loads, and got it to show once the 1st video is finished playing. Just need to know how to make it to autoplay.


Solution

  • $("#video2")[0].play();
    

    should play the second video.