0
点赞
收藏
分享

微信扫一扫

js video清空src


let video = documnet.querySelector('video')
try {
if ('srcObject' in video) {
video.srcObject = null;
} else {
// Avoid using this in new browsers, as it is going away.
video.src = null;
}
} catch(e){
console.log(e)
}
注意
  • ​src​​​置为​​''​​​无法清空​​video​​​ 且报错​​Uncaught TypeError: Failed to set the 'srcObject' property on 'HTMLMediaElement': Failed to convert value to 'MediaStream'.​
  • ​src​​​置为​​null​​​可清空​​video​​​ 但报错​​Cannot set properties of null (setting 'srcObject')​​​会阻塞后续执行 - 解决办法:用​​try catch​​ 包裹


举报

相关推荐

0 条评论