Is there a way to keep two videos synchronized on a web page without plugins?

Is there a way to use two HTML5 tags per page and sync the video? Does this mean that if the first video is 15.2 seconds, the second video is 15.2 seconds?

I looked around and found SMIL, but it looks like it only works in IE. I also tried to implement something of my own using jQuery and jMediaElement, but there seem to be many cases where a video can go out of sync.

Has this been done before?

+6
html5 video
source share
4 answers

Found. It was at http://html5demos.com .

Checkout demo .. works fine (well, almost) on Chrome for me.

The source is available on the page.

0
source share

The demo presented on html5demos works, but it can easily get out of sync.

Here is an article providing a solution that uses requestAnimationFrame (information about this: Leaner, Meaner, Faster Animations with requestAnimationFrame , Animation using javascript: from setInterval to requestAnimationFrame ), and it is much better: HTML5 Video: Synchronization of playback of two videos .

Please note that the demo provided there (hosted in jsfiddle) has an incorrect js source reference. I updated it on this new page:

http://jsfiddle.net/aqUNf/1/

Remember browser support, this feature is supported by Firefox, Chrome and Safari 6 and IE 10 (see table for more information). Otherwise, it returns to setInterval, the witch does not provide the same performance and battery advantage.

(He uses Popcorn.js , which is a really nice Mozilla project)

And here is the code (directly taken from the demo):

var videos = { a: Popcorn("#a"), b: Popcorn("#b"), }, scrub = $("#scrub"), loadCount = 0, events = "play pause timeupdate seeking".split(/\s+/g); // iterate both media sources Popcorn.forEach( videos, function( media, type ) { // when each is ready... media.listen( "canplayall", function() { // trigger a custom "sync" event this.trigger("sync"); // set the max value of the "scrubber" scrub.attr("max", this.duration() ); // Listen for the custom sync event... }).listen( "sync", function() { // Once both items are loaded, sync events if ( ++loadCount == 2 ) { // Iterate all events and trigger them on the video B // whenever they occur on the video A events.forEach(function( event ) { videos.a.listen( event, function() { // Avoid overkill events, trigger timeupdate manually if ( event === "timeupdate" ) { if ( !this.media.paused ) { return; } videos.b.trigger( "timeupdate" ); // update scrubber scrub.val( this.currentTime() ); return; } if ( event === "seeking" ) { videos.b.currentTime( this.currentTime() ); } if ( event === "play" || event === "pause" ) { videos.b[ event ](); } }); }); } }); }); scrub.bind("change", function() { var val = this.value; videos.a.currentTime( val ); videos.b.currentTime( val ); }); // With requestAnimationFrame, we can ensure that as // frequently as the browser would allow, // the video is resync'ed. function sync() { videos.b.currentTime( videos.a.currentTime() ); requestAnimFrame( sync ); } sync(); 
+4
source share

The only way to play videos without plugins is HTML5 or SVG <video>. There is no reliable method for saving two HTML5 videos, but if accurate synchronization is not critical, you can probably get close to it just by calling the game () at the same time or calling play () and pause () on the two videos to get them in approximate synchronization, as Simeon hinted.

As for SVG <video>, SVG already has a small (and modified) subset of SMIL, so it may already be supported in the specification, but as far as I know, the browser will not handle this properly.

+1
source share

It seems that even Opera has this problem (10 MAR, 2010):

There is currently no good API for synchronizing things with the timeline of a video , such as titles or info boxes. The specification had for this purpose “cue ranges” (which used to be “key points”); something similar is expected to be added in the future

http://dev.opera.com/articles/view/everything-you-need-to-know-about-html5-video-and-audio/

Btw, the article is really interesting, and you might find some helpful tips in it.

0
source share

All Articles