html5调用本地摄像头播放视频但是浏览器报错如下 请问这个应该怎么解决 10
file:///C:/Users/Faceall/Desktop/[object%20MediaStream]Failedtoloadresource:net::ERR_...
file:///C:/Users/Faceall/Desktop/[object%20MediaStream] Failed to load resource: net::ERR_FILE_NOT_FOUND
2.html:1 Uncaught (in promise) DOMException: Failed to load because no supported source was found.
具体代码如下
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<script>
//获取摄像头的视频流并显示在Video 签中
window.addEventListener("DOMContentLoaded", function () {
var
video = document.getElementById("video"),
videoObj = { "video": true },
errBack = function (error) {
console.log("Video capture error: ", error.code);
};
if (navigator.getUserMedia) {
navigator.getUserMedia(videoObj, function (stream) {
video.src = stream;
video.play();
}, errBack);
} else if (navigator.webkitGetUserMedia) {
navigator.webkitGetUserMedia(videoObj, function (stream) {
video.src = window.webkitURL.createObjectURL(stream);
video.play();
}, errBack);
}
}, false);
</script>
</head>
<body>
<div id="contentHolder">
<video id="video" width="320" height="320" autoplay></video>
</div>
</body>
</html> 展开
2.html:1 Uncaught (in promise) DOMException: Failed to load because no supported source was found.
具体代码如下
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<script>
//获取摄像头的视频流并显示在Video 签中
window.addEventListener("DOMContentLoaded", function () {
var
video = document.getElementById("video"),
videoObj = { "video": true },
errBack = function (error) {
console.log("Video capture error: ", error.code);
};
if (navigator.getUserMedia) {
navigator.getUserMedia(videoObj, function (stream) {
video.src = stream;
video.play();
}, errBack);
} else if (navigator.webkitGetUserMedia) {
navigator.webkitGetUserMedia(videoObj, function (stream) {
video.src = window.webkitURL.createObjectURL(stream);
video.play();
}, errBack);
}
}, false);
</script>
</head>
<body>
<div id="contentHolder">
<video id="video" width="320" height="320" autoplay></video>
</div>
</body>
</html> 展开
2018-05-16
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
video.src = stream;改成video.srcObject = stream;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询