admin管理员组文章数量:1406951
I am working on one project in which I need to show the timestamp of video in actual time format as "01:12:50". Below is my code which return the current time of video as frame rate ie "12.526". Can anyone help me how I can change it to actual time or is there any way that I can directly get the video timestamp using HTML and JavaScript.
<video id="myVideo" width="740px" height="600px"></video>
<div id="timer"> </div>
<script>
document.getElementById("myVideo").addEventListener('timeupdate', function() {
document.getElementById("timer").innerHTML = this.currentTime;
currentTime = this.currentTime;
});
</script>
I am working on one project in which I need to show the timestamp of video in actual time format as "01:12:50". Below is my code which return the current time of video as frame rate ie "12.526". Can anyone help me how I can change it to actual time or is there any way that I can directly get the video timestamp using HTML and JavaScript.
<video id="myVideo" width="740px" height="600px"></video>
<div id="timer"> </div>
<script>
document.getElementById("myVideo").addEventListener('timeupdate', function() {
document.getElementById("timer").innerHTML = this.currentTime;
currentTime = this.currentTime;
});
</script>
Share
Improve this question
edited Feb 28, 2023 at 3:24
imxitiz
3,9873 gold badges12 silver badges35 bronze badges
asked Jul 6, 2021 at 17:08
UsmanUsman
2,0292 gold badges18 silver badges30 bronze badges
1
- 1 currentTime returns current time in seconds. So "12.526" (in your question) is not framerate but current timing of the video in seconds. – Shyam Commented Jul 6, 2021 at 17:24
1 Answer
Reset to default 4You can just do a simple math!
document.getElementById("myVideo").addEventListener('timeupdate', function() {
var hours=parseInt(video.currentTime/(60*60),10);
var minutes = parseInt(video.currentTime / 60, 10);
var seconds = video.currentTime % 60;
if (hours==0) {
documentgetElementById("timer").innerHTML=minutes+":"+seconds.toFixed(0)
} else {
document.getElementById("timer").innerHTML=hours+":"+minutes+":"+seconds.toFixed(0)
}
});
You may or may not need if else code. You can change as you want.
本文标签: javascriptHow to get video timestamp in HTMLStack Overflow
版权声明:本文标题:javascript - How to get video timestamp in HTML - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744936066a2633193.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论