動画の再生時間と実際の時間を表示したい場合は、メディア動画プレーヤーHTML5 JS
私はJSのHTMLMediaElement APIを使用しています。
すべてが動作しています(再生、一時停止、再起動、など)が、再生時間と現在の時間は機能していません。理由はわかりません。
<div class="wrap_video">
<video id="video" width="298" height="240">
<source src="videos/windowsill.mp4" type="video/mp4">
Désolé, votre navigateur ne vous permet pas de visualiser cette vidéo.
</video>
</div>
<div class="datas">
<span id="currentTime"><script>document.write(currentTime);</script></span>
<span id="duration"><script>document.write(duration);</script></span>
</div>
<div id="buttonbar">
<button id="restart" class="btn btn-default" onclick="restart();">
<span class="glyphicon glyphicon-repeat"></span>
</button>
<button id="rewind" class="btn btn-default" onclick="skip(-10)">
<span class="glyphicon glyphicon-fast-backward"></span><!--<<-->
</button>
<button id="play" class="btn btn-default" onclick="playPause()">
<span class="glyphicon glyphicon-play"></span><!-->-->
</button>
<button id="fastForward" class="btn btn-default" onclick="skip(10)">
<span class="glyphicon glyphicon-fast-forward"></span>
</button>
</div>
</div>
そして、私のJS:
/**
* Play or Pause the video
*/
function playPause() {
var video = document.getElementById("video");
var button = document.getElementById("play");
var currentTime = 0;
currentTime += document.getElementById("video").currentTime;
var duration = document.getElementById("video").duration;
if (video.paused) {
video.play();
button.innerHTML = "<span class=\"glyphicon glyphicon-pause\"></span>";
} else {
video.pause();
button.innerHTML = "<span class=\"glyphicon glyphicon-play\"></span>";
}
}
/**
* Restart the video
*/
function restart() {
var video = document.getElementById("video");
video.currentTime = 0;
}
/**
* Skip the video to the given value
*
* @param int value The value
*/
function skip(value) {
var video = document.getElementById("video");
video.currentTime += value;
}
は、実際に私はただ、現在の時刻と期間
を表示したい私はこれが私のコードです^^罰金してください通常、JSのコードをいけません
編集: これで今私はそれを持っています:
setInterval(function() {
document.getElementById("currentTime").innerHTML = document.getElementById("video").currentTime;
}, 1000);
var duration = document.getElementById("video").duration;
document.getElementById("duration").innerHTML = duration;
しかし、今私の問題は、私が代わりに代わり20:03の午後12時とはNaNの[ObjectHTMLSpanElement]持っているということです...
をあなたの 'のvar currentTime'がちょうどに更新されているようです再生または一時停止、私はこれがあなたの意図であるかどうかわからない –
あなたはこれを見ていましたか:http://stackoverflow.com/questions/6380956/current-duration-time-of-html5-video? – caramba
'document.write'はページのレンダリング時に一度だけ実行されますが、動的バインディングではありません。 – pawel