Ich möchte die Dauer meines Videos und die tatsächliche Zeit zeigen.Media Video Player HTML5 JS
Dafür verwende ich HTMLMediaElement API in JS.
Alles funktioniert (spielen, Pause, Neustart, ...) aber die Dauer und die aktuelle Zeit funktionieren nicht und ich weiß nicht warum. Ich habe nicht in der Regel Code in JS also bitte fein ^^
Dies ist mein Code:
<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>
Und meine 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;
}
Eigentlich
Ich möchte nur aktuelle Uhrzeit und Dauer zeigenEdit: so jetzt Ok ich habe das: Für die aktuelle Zeit
setInterval(function() {
document.getElementById("currentTime").innerHTML = document.getElementById("video").currentTime;
}, 1000);
var duration = document.getElementById("video").duration;
document.getElementById("duration").innerHTML = duration;
aber jetzt mein Problem ist, dass ich [ObjectHTMLSpanElement] anstelle von 00.00 und NaN statt 20.03 ...
scheint Ihr 'var currentTime' wird gerade aktualisiert play oder pause, ich weiß nicht, ob das deine Absicht ist –
hast du dir das angeschaut: http://stackoverflow.com/questions/6380956/current-duration-time-of-html5-video? – caramba
'document.write' wird nur einmal ausgeführt, wenn die Seite gerendert wird, es handelt sich nicht um eine dynamische Bindung. – pawel