js获取视频时长
2024-08-19 Umming js常用代码 评论(0) 浏览(476)
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.7.1/jquery.min.js"></script> <div class="video"> <video src="../media/145.mp4" controls></video> </div> <div class="video"> <video src="../media/demo.mp4" controls></video> </div> <script> //jquery获取对象 //var $video = $('#myVideo'); // 转换为DOM对象 //var video = $video[0]; // 或者使用 $video.get(0) function getSecond(seconds) { var minutes = Math.floor(seconds / 60); var remainingSeconds = seconds % 60; var minuteString = minutes < 10? '0' + minutes : minutes; var secondString = remainingSeconds < 10? '0' + remainingSeconds : remainingSeconds; return minuteString + ':' + Math.floor(secondString); } function getVideoDurations() { $(".video").each(function(){ var that = $(this); var video = that.find('video').get(0); video.addEventListener('loadedmetadata', function () { that.append('<span class="vtime">'+getSecond(this.duration)+'</span>') //console.log('视频的时长:' + getSecond(this.duration)); }) }) } getVideoDurations(); </script>
标签: js代码
本文链接:https://www.umming.com/js/331.html
声明:本站信息由网友自行发布或来源于网络,真实性、合法性由发布人负责,请仔细甄别!本站只为传递信息,我们不做任何双方证明,也不承担任何法律责任。文章内容若侵犯你的权益,请联系本站删除!
也许你还会对下面的内容感兴趣:
发表评论: