html5demos पर प्रस्तुत किया गया डेमो काम करता है लेकिन यह आसानी से सिंक से बाहर जा सकता है।
यहां एक ऐसा समाधान प्रदान करने वाला एक लेख है जो अनुरोध का उपयोग करता हैएनीमेशन फ्रेम (इसके बारे में जानकारी: Leaner, Meaner, Faster Animations with requestAnimationFrame, Animating with javascript: from setInterval to requestAnimationFrame) और यह बहुत बेहतर है: HTML5 Video: Synchronizing Playback of Two Videos।
ध्यान दें कि वहां प्रदान किए गए डेमो (जेएसफ़िल्ड पर होस्ट किए गए) के पास जेएस स्रोत पर एक गलत लिंक है। मैं इस नए पेज पर यह अद्यतन:
http://jsfiddle.net/aqUNf/1/
भालू मन ब्राउज़र समर्थन में, इस सुविधा फायरफॉक्स, क्रोम के द्वारा समर्थित है, और सफारी 6 और आईई 10 से (अधिक जानकारी के लिए table देखें)। अन्यथा यह सेट अंतराल पर वापस आ जाता है, चुड़ैल एक ही प्रदर्शन और बैटरी बचत लाभ प्रदान नहीं करता है।
(यह रास्ता है, जो मोज़िला द्वारा वास्तव में एक अच्छा परियोजना है द्वारा Popcorn.js उपयोग करता है) और यहाँ कोड (सीधे डेमो से लिया गया) है:
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();
दिलचस्प मैं डेमो दर्शाता देखा एक बिल्ली के दो बार एक ही वीडियो और दोनों सिंक्रनाइज़ किए गए थे। यह सही नहीं था, लेकिन मैकबुक या तो सबसे शक्तिशाली मशीन नहीं है। याद नहीं किया जा सकता है कि मैंने इसे देखा, lemme google – Anurag