满意答案
ct927112
推荐于 2016.02.25
采纳率:42% 等级:9
已帮助:211人
html5中的video这个标签是引入视频的,通过navigator.getUserMedia去获取摄像头的视频流,所以要在事件里用关闭的代码都不能执行关闭摄像头,只有关闭网页,摄像头才关闭。
html5打开摄像头代码:
Smart Home - Camerafunction init(t){
accessLocalWebCam("camera_box");
}
// Normalizes window.URL
window.URL = window.URL || window.webkitURL || window.msURL || window.oURL;
// Normalizes navigator.getUserMedia
navigator.getUserMedia = navigator.getUserMedia ||
navigator.webkitGetUserMedia|| navigator.mozGetUserMedia ||
navigator.msGetUserMedia;
function isChromiumVersionLower() {
var ua = navigator.userAgent;
var testChromium = ua.match(/AppleWebKit\/.* Chrome\/([\d.]+).* Safari\//);
return (testChromium && (parseInt(testChromium[1].split('.')[0]) < 19));
}
function successsCallback(stream) {
document.getElementById('camera_errbox').style.display = 'none';
document.getElementById('camera_box').src = (window.URL
&& window.URL.createObjectURL) ?
window.URL.createObjectURL(stream) : stream;
}
function errorCallback(err) {
}
function accessLocalWebCam(id) {
try {
// Tries it with spec syntax
navigator.getUserMedia({ video: true }, successsCallback, errorCallback);
} catch (err) {
// Tries it with old spec of string syntax
navigator.getUserMedia('video', successsCallback, errorCallback);
}
}
#camera_errbox{
width:320px; height:auto; border:1px solid #333333; padding:10px;
color:#fff; text-align:left;margin:20px auto;
font-size:14px;
}
#camera_errbox b{
padding-bottom:15px;
}
class="icon_12">
class="sp_title_text">Camera
请点击“允许”按钮,授权网页访问您的摄像头!
00分享举报