Quantcast
Channel: Dynamically loading and autoplaying HTML5 video - Stack Overflow
Viewing all articles
Browse latest Browse all 2

Answer by apires for Dynamically loading and autoplaying HTML5 video

$
0
0

Use .play()after adding it's src.

jQuery(document).ready(function($) {"use strict";  $("video").each(function() {    var $source = $(this).find('source');    var src = $source.attr('data-src');    $source.removeAttr('data-src');    $source.attr('src', src);    $source.detach().appendTo($(this))    $(this).get(0).play();  });});
video {  width: 420px;  height: 230px;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><video loop="loop" poster="http://placehold.it/420x230"><source type="video/mp4" data-src="http://techslides.com/demos/sample-videos/small.mp4"></video>

Viewing all articles
Browse latest Browse all 2

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>