views:

596

answers:

2

I'm able to get two videos to play sequentially, (and without pause!) with this code from Apple, (see section 2-4)...

http://developer.apple.com/safari/library/documentation/AudioVideo/Conceptual/Using_HTML5_Audio_Video/ControllingMediaWithJavaScript/ControllingMediaWithJavaScript.html

...Yet completely lost as to how to play a 3rd or 5th video. Trouble is I'm a Javascript noob :-(, so if you figure this out please share as much of your code as possible.

Thanks much!

+3  A: 

The first video's ended => Start second video
The second video's ended => Start third video
The third video's ended => Start fourth video
The fourth video's ended => Start first video

It's just redefining the ended event handler nonstop...
You could also use a variable starting at 0. increment it each time and set SRC to i%video_count

var i = 0;
var sources = ["http://www.a.com/blargh.m4v", "http://www.b.com/blargh.m4v"];
videoElement.addEventListener('ended', function(){
   videoElement.src = sources[(++i)%sources.length];
   videoElement.load();
   videoElement.play();
}, false);

...The above code assumes the video is already playing onload, like your example

ItzWarty
A: 

Almost exactly what I am trying to do...one difference. How can I have the sources variable be set by parsing a txt file?..As in being able to use a playlist. Ultimately I need for the javascript function to fetch the playlist from an http address, then i dont have to set up some rsync like mechanism outside of the webpage to do this for me.

What is posted here so far is very encouraging that i will be able to accomplish this.

Thanks to all!

Ron FIsh