本文介绍了getUserMedia冻结在Android Chrome的第一帧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在桌面浏览器上有一个支持getUserMedia Api的工作代码,我可以在div videoPreview
中正确看到我的网络摄像头的视频预览。但是,当在Android设备上运行时,当我接受在Chrome浏览器中共享时,此相同的代码会使用我的前置摄像头拍摄照片,然后预览会冻结在第一帧。
I have a working code on desktop browsers supporting getUserMedia Api, I can correctly see a video preview of my webcam in the div videoPreview
. However, when running on Android device, this same code takes a picture with my front camera when I accept to share it in Chrome browser, then the preview keeps frozen on this first frame.
navigator.getMedia = (navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia);
navigator.getMedia(
// constraints
{video:true, audio:false},
// success callback
function (mediaStream) {
var video = document.getElementById('videoPreview');
video.src = window.URL.createObjectURL(mediaStream);
video.play();
},
//handle error
function (error) {
console.log(error);
}
)
推荐答案
对于那些遇到同样问题的用户:我通过添加 autoplay
< video>
标签。
For those encountering same problem : I fixed it by adding
autoplay
attribute to my <video>
tag.
我希望这将帮助别人。
这篇关于getUserMedia冻结在Android Chrome的第一帧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!