首页 > 编程知识 正文

谷歌浏览器h5播放模式,h5视频在谷歌浏览器自动播放

时间:2023-05-06 10:05:19 阅读:236064 作者:4381

直接附上代码,请参考 有一定的兼容性问题 ,兼容性的代码我就不附上了哈
提示哈 可以使用try catch

<!DOCTYPE html><html><head><meta charset="utf-8"><title>h5调用电脑摄像头</title><style>.live{height: 400px;width: 400px;margin: 0 auto;}#video{object-fit: fill;}</style></head><body><div class="live"><video id="video" width="400px" height="400px"></video><button id="open">打开摄像头</button></div><script>var video = document.getElementById('video'); function liveVideo(){ navigator.getUserMedia({ video: true }, function(stream){video.srcObject=stream; // 将获取到的视频流对象转换为地址 video.play(); }, function(error){ console.log(error); }); }document.getElementById('open').onclick=function(){liveVideo();}</script></body></html>

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。