Can I use a <video>
or <audio>
tag to play a playlist, and to control them?
My goal is to know when a video/song has finished to play and take the next and change its volume.
HTML5 features include native audio and video support without the need for Flash. The HTML5 <audio> and <video> tags make it simple to add media to a website. You need to set src attribute to identify the media source and include a controls attribute so the user can play and pause the media.
<video>: The Video Embed element. The <video> HTML element embeds a media player which supports video playback into the document. You can use <video> for audio content as well, but the <audio> element may provide a more appropriate user experience.
you could load next clip in the onend event like that
<script type="text/javascript"> var nextVideo = "path/of/next/video.mp4"; var videoPlayer = document.getElementById('videoPlayer'); videoPlayer.onended = function(){ videoPlayer.src = nextVideo; } </script> <video id="videoPlayer" src="path/of/current/video.mp4" autoplay autobuffer controls />
More information here
I created a JS fiddle for this here:
http://jsfiddle.net/Barzi/Jzs6B/9/
First, your HTML markup looks like this:
<video id="videoarea" controls="controls" poster="" src=""></video> <ul id="playlist"> <li movieurl="VideoURL1.webm" moviesposter="VideoPoster1.jpg">First video</li> <li movieurl="VideoURL2.webm">Second video</li> ... ... </ul>
Second, your JavaScript code via JQuery library will look like this:
$(function() { $("#playlist li").on("click", function() { $("#videoarea").attr({ "src": $(this).attr("movieurl"), "poster": "", "autoplay": "autoplay" }) }) $("#videoarea").attr({ "src": $("#playlist li").eq(0).attr("movieurl"), "poster": $("#playlist li").eq(0).attr("moviesposter") }) })
And last but not least, your CSS:
#playlist { display:table; } #playlist li{ cursor:pointer; padding:8px; } #playlist li:hover{ color:blue; } #videoarea { float:left; width:640px; height:480px; margin:10px; border:1px solid silver; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With