实验
本实验基于Chrome浏览器进行。
先构建一个网页,内部包含2个视频。
<!doctype html>
<html>
<head>
<title>HTML5 Synchronize Video Test</title>
</head>
<body>
<h1>HTML5 Synchronize Video Test</h1>
<div>
<video id="v1" controls src="video_001.mp4" style="width:256px" muted="true">
</video>
<video id="v2" controls src="video_001_copy.mp4" style="width:256px">
</video>
</div>
</body>
</html>
加入播放进度控制脚本(script
):
<script>
// sync 2nd (right) video to playing position of 1st (left) video
window.onload = function(){
var v1 = document.getElementById('v1');
v1.addEventListener("play", function() {
document.getElementById('v2').play();
});
v1.addEventListener("pause", function() {
document.getElementById('v2').pause();
});
v1.addEventListener("seeking", function() {
document.getElementById('v2').currentTime = v1.currentTime;
});
v1.addEventListener("seeked", function() {
document.getElementById('v2').currentTime = v1.currentTime;
});
}
</script>
参考资料:
[1] HTML5 Synchronize Video Test
[2] HTML 元素