點評:Video對象是HTML5中新增的一個對象,支持多種不同格式的視頻在線播放,功能比較強大,Video對象可以通過ontimeupdate事件來報告當前的播放進度,下面為大家介紹下Video對象ontimeupdate事件的問題,感興趣的朋友可以參考下哈
日期在做一個視頻播放的頁面,其中用到了HTML5的Video對象,這個是HTML5中新增的一個對象,支持多種不同格式的視頻在線播放,功能比較強大,而且還擴展了許多事件,可以通過JavaScript腳本來對視頻播放進行控制。參考下面兩個鏈接:復制代碼
代碼如下:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
<title></title>
</head>
<body>
<script type="text/javascript">
function timeUpdate() {
document.getElementById('time').innerHTML = video.currentTime;
}
function durationChange() {
document.getElementById('duration').innerHTML = video.duration;
}
function seekVideo() {
document.getElementById('video').currentTime = document.getElementById('seekText').value;
}
window.onload = function () {
var videoPlayer = document.getElementById("video");
videoPlayer.ontimeupdate = function () { timeUpdate(); };
};
</script>
<div>
<video controls="controls"
poster="./images/videoground1.png"
src="./videoSource/video1.mp4"
ondurationchange="durationChange()" />
</div>
<div>Time: <span>0</span> of <span>0</span> seconds.</div>
<div>
<input type="text" />
<input type="button" value="Seek Video" />
</div>
</body>
</html>
復制代碼
代碼如下:
video.ontimeupdate = function () { getCurrentVideoPosition(); };
復制代碼
代碼如下:
videoPlayer.addEventListener("timeupdate", function () { getCurrentVideoPosition(); }, false);
新聞熱點
疑難解答