我正在使用 JavaScript 记录用户屏幕,然后在页面的视频标签中播放并下载它。现在它可以正常播放浏览器视频标签,但下载后无法播放
这是我的代码
let btn = document.querySelector('button')
btn.addEventListener('click', async function (){
let stream = await navigator.mediaDevices.getDisplayMedia({
video: true
})
let mediaRecorder = new MediaRecorder(stream)
let chunks = []
mediaRecorder.addEventListener('dataavailable', function (e) {
chunks.push(e.data)
})
mediaRecorder.addEventListener('stop', function () {
let blob = new Blob(chunks, { 'type': 'video/webm' })
// Working fine
let video = document.querySelector('video')
video.src = URL.createObjectURL(blob)
// Downloaded video is not playing
let a = document.createElement('a')
a.href = URL.createObjectURL(blob)
a.download = 'video.webm'
a.click()
})
mediaRecorder.start()
})```