Skip to content

Instantly share code, notes, and snippets.

@remcotolsma
Last active February 11, 2016 10:00
Show Gist options
  • Save remcotolsma/fe355f54da4c4cee9200 to your computer and use it in GitHub Desktop.
Save remcotolsma/fe355f54da4c4cee9200 to your computer and use it in GitHub Desktop.
Play HTML5 videos in a row.
<!-- Videos used from http://www.coverr.co/ -->
<video id="test" autoplay src="Acro/WEBM/Acro.webm" type="video/webm" class="fillWidth" controls>
</video>
<script type="text/javascript">
var videoSource = new Array();
videoSource[0] = 'Acro/WEBM/Acro.webm';
videoSource[1] = 'Coverr-beach/Coverr-beach.webm';
var videoCount = videoSource.length;
function videoPlay( videoNum ) {console.log( videoSource[ videoNum ] );
document.getElementById( "test" ).setAttribute( "src", videoSource[ videoNum ] );
document.getElementById( "test" ).load();
document.getElementById( "test" ).play();
}
document.getElementById( 'test' ).addEventListener( 'ended', myHandler, false );
i = 0;
function myHandler() {
i++;
if ( i > ( videoCount - 1 ) ) {
i = 0;
videoPlay( i );
} else {
videoPlay( i );
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment