由於業務需求,需要上傳視頻,但是視頻的時長都吃重后台管理和數據庫中手動填寫的。
<html>
<body>
<input type="file" id="file" onchange="onInputFileChange()">
<audio id="audio_id" controls autoplay loop>Your browser can't support HTML5 Audio</audio>
<script>
function onInputFileChange() {
var file = document.getElementById('file').files[0];
var url = URL.createObjectURL(file);
console.log(url);
var videos =document.getElementById("audio_id")
videos.src = url;
setTimeout(function(){
if(videos.readyState>0){
var minutes = parseInt(videos.duration / 60, 10);
var seconds = videos.duration % 60;
console.log(minutes)
alert(seconds)
}
},500)
}
</script>
</body>
</html>