const videoRef = useRef()
const handleUpload = async (event) => {
const file = event.target.files[0]
const { type } = file
if (!/^video\//.test(type)) {
Toast.info('请上传视频', 2)
return
}
if (videoRef.current) video.current = ''
let audioElement = new Audio(URL.createObjectURL(file))
audioElement.muted = true
audioElement.play().then(() => audioElement.pause())
audioElement.addEventListener('loadedmetadata', async (_event) => {
const seconds = parseInt(audioElement.duration)
console.log('----seconds', seconds)
})
}
<input
className={cn.input}
type={'file'}
accept={'video/*'}
ref={videoRef}
onChange={(e) => handleUpload(e)}
/>
audio语音在ios下获取不到duration总时长问题