我對HTML5
很新。我嘗試使用以下HTML5
代碼訪問我的手機上的相機。它始終顯示「不支持本地網絡攝像頭」。看來我的手機瀏覽器(safari和android 2.1網頁瀏覽器)不支持相機。HTML5:攝像頭訪問
您能否告訴我應該使用哪種瀏覽器訪問相機?
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, maximum-scale=1.0">
<style>
body {width: 100%;}
canvas {display: none;}
</style>
<script>
var video, canvas, msg;
var load = function() {
video = document.getElementById('video');
canvas = document.getElementById('canvas');
msg = document.getElementById('error');
if(navigator.getUserMedia) {
video.onclick = function() {
var context = canvas.getContext("2d");
context.drawImage(video, 0, 0, 240, 320);
var image = {"demo" : {
"type" : "device",
"image" : canvas.toDataURL("image/png")
}};
};
var success = function (stream) {
video.src = stream;
};
var error = function (err) {
msg.innerHTML = "Error: " + err.code;
};
navigator.getUserMedia('video', success, error);
} else {
msg.innerHTML = "Native web camera not supported :(";
}
};
window.addEventListener('DOMContentLoaded', load, false);
</script>
</head>
<body>
<video id="video" width="240" height="320" autoplay> </video>
<p id="error">Click on the video to send a snapshot to the receiving screen</p>
<canvas id="canvas" width="240" height="320"> </canvas>
</body>
</html>
HTML5的攝像頭API還很新,它甚至不是很廣泛的支持*臺式機*,更不用說移動設備。你不能依賴它可用。 – Kitsune 2012-02-24 13:27:12
看到這裏的演示HTML5的麥克風和攝像頭訪問在Chrome ..這是最新鮮的東西.. http://www.youtube.com/watch?feature = player_detailpage&v = VP0SV3YWOWA#t = 1425s – Lloyd 2012-02-24 14:49:28
HTML5移動版不再支持「流血邊緣」 - 請參閱http://stackoverflow.com/a/13489553/957950瞭解如何直接從相機獲取圖片,或者通過http: //mobilehtml5.org/ts/?id=23。歡迎來到未來!仍然沒有懸浮板,對不起。 :( – brichins 2016-02-18 17:21:22