Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML 5 video or audio playlist

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.

like image 374
xdevel2000 Avatar asked Mar 31 '10 09:03

xdevel2000


People also ask

Does HTML5 support audio and video?

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.

What is the correct HTML5 element for playing audio and video files?

<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.


2 Answers

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

like image 90
markcial Avatar answered Oct 26 '22 23:10

markcial


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; }​ 
like image 41
Maziar Barzi Avatar answered Oct 27 '22 00:10

Maziar Barzi