映像の再生が終了したかどうか調べる

説明

videoタグで指定された映像の再生が終了したかどうか調べるにはendedプロパティを参照します。trueなら再生終了、falseなら再生中であることを示します。[サンプルはFirefox 3.6以降で動作]

サンプルプログラム

【HTML】
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<title>Sample</title>
<link rel="stylesheet" href="css/main.css" type="text/css" media="all">
<script type="text/javascript" src="js/sample.js"></script>
</head>
<body>
<h1>映像の再生が終了したかどうか調べる</h1>
<video id="myVideo" controls>
<source src="movie/sunflower.mov">
<source src="movie/sunflower.ogg">
</video>
<div id="result></div>
</body>
</html>


【sample.js】
window.onload = checkTime;
function checkTime(){
var vObj = document.getElementById("myVideo");
document.getElementById("result").innerHTML = vObj.ended;
setTimeout("checkTime()", 50);
}
サンプルを実行
[戻る]