La demostración que se presentó en html5demos funciona pero puede desfasarse fácilmente.
He aquí un artículo que proporciona una solución que hace uso de requestAnimationFrame (información al respecto: Leaner, Meaner, Faster Animations with requestAnimationFrame, Animating with javascript: from setInterval to requestAnimationFrame) y es mucho mejor: HTML5 Video: Synchronizing Playback of Two Videos.
Tenga en cuenta que la demostración proporcionada allí (alojada en jsfiddle) tiene un enlace incorrecto en una fuente js. He actualizado en esta nueva página:
http://jsfiddle.net/aqUNf/1/
oso en el apoyo del navegador mente, esta función es compatible con Firefox, Chrome, Safari y desde 6 e IE 10 (véase table para más detalles). De lo contrario, vuelve a setInterval, que no ofrece el mismo rendimiento y la misma ventaja de ahorro de batería.
(Se utiliza Popcorn.js por cierto, que es un muy buen proyecto por Mozilla)
Y aquí está el código (directamente tomado de la 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();
interesante que vi una demo que muestra el el mismo video de un gato dos veces y ambos se sincronizaron. no era perfecto, pero una Macbook tampoco es la máquina más poderosa. No recuerdo dónde vi eso, déjame google – Anurag