H5 input video 自拍 获取视频时长时间 和大小 以上传限制


限苹果手机,以下自测通过,安卓手机不支持 loadedmetadata

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<input type="file" accept="video/*" capture="user" id='upload'>
<button onclick='getVideoTime()'>获取时长</button>
</body>
<script>
    function getVideoTime() {
      let fileVIdeo =  document.getElementById("upload")
      const pickOne =fileVIdeo.files[0]
      window.URL = window.URL || window.webkitURL
      const url = window.URL.createObjectURL(pickOne)
      const audioElement = new Audio(url)
      audioElement.addEventListener('loadedmetadata', (_event) => {
        const duration = audioElement.duration
        console.log('视频时长:' + duration + '')
        if (duration > 5) {
          this.$showToast('请控制录制时间在5秒之内')
          return
        }
        const size = pickOne.size / 1024 / 1000
        if (size > 5) {
          this.$showToast('视频文件过大,请控制在3秒之内')
          return
        }
        this.toCheckFace(event)
      })

    }
</script>
</html>
 


 

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM