I want to display the video currentTime
and duration
in a different format.
The way it displays it now is:
0:9 / 0:33
I want it to display it like this:
00:09 / 00:33
Or if the video duration is more than 1 minute
03:10 / 12:27
the current code i have right now
video.on('timeupdate', function() {
// Set to minute and seconds
var time = video[0].currentTime;
var minutes = Math.floor(time / 60);
var seconds = Math.floor(time);
// Set the current play value
currentTimer.text(minutes + ':' + seconds);
});
video.on('loadedmetadata', function() {
// Set to minute and seconds
var time = video[0].duration;
var minutes = Math.floor(time / 60);
var seconds = Math.floor(time);
// Set the video duration
durationTimer.text(minutes + ':' + seconds);
});
This code should do what you want :
function format(s) { var m = Math.floor(s / 60); m = (m >= 10) ? m : "0" + m; s = Math.floor(s % 60); s = (s >= 10) ? s : "0" + s; return m + ":" + s; } alert(format(120)); alert(format(250)); alert(format(31));
</body> <script> var myVideoPlayer = document.getElementById('video-element'), meta = document.getElementById('meta'); myVideoPlayer.addEventListener('loadedmetadata', function () { var duration = myVideoPlayer.duration; meta.innerHTML = "Duration is " + duration.toFixed(2) + " seconds." }); </script>
<div class="col-md-12"> <div class="col-md-8" id='player'> <video style="width:100%;height:auto;" id='video-element' controls preload controlsList="nodownload"> <source src="../videos/SampleVideo_1280x720_5mb.mp4" id="s1" type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"'> <source src="../videos/sample1.ogg" type='video/ogg; codecs="theora, vorbis"'> </video> </div> <div class="col-md-4"> <div class="box-body"> <hr style="margin: 28px 0px 10px;"> <div class="col-md-12"> <video width="168" height="94" id='cc'> <source src="../videos/SampleVideo_1280x720_5mb.mp4" id="s1" type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"'> <source src="../videos/sample1.ogg" type='video/ogg; codecs="theora, vorbis"'> </video> </div> </div> </div> <div id="meta"></div> </div>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.