我目前正在運行Chrome 11並試圖訪問getUserMedia
以支持HTML5原生音頻和視頻流支持,但我收到一條錯誤消息,說明navigator.getUserMedia
未定義。如果不支持,我該如何訪問它,或者我需要等到Chrome整合後才能使用它?如何訪問navigator.getUserMedia()?
這是我使用測試getUserMedia
的代碼,我發現
<h1>Snapshot Kiosk</h1>
<section id="splash">
<p id="errorMessage">Loading...</p>
</section>
<section id="app" hidden>
<p><video id="monitor" autoplay></video> <canvas id="photo"></canvas>
<p><input type=button value="📷" onclick="snapshot()">
</section>
<script>
navigator.getUserMedia('video user', gotStream, noStream);
var video = document.getElementById('monitor');
var canvas = document.getElementById('photo');
function gotStream(stream) {
video.src = URL.getObjectURL(stream);
video.onerror = function() {
stream.stop();
noStream();
}
video.onloadedmetadata = function() {
canvas.width = video.videoWidth;
canvas.height = video.videoHeight;
document.getElementById('splash').hidden = true;
document.getElementById('app').hidden = false;
}
}
function noStream() {
document.getElementById('errorMessage').textContent = 'No camera available.';
}
function snapshot() {
canvas.getContext('2d').drawImage(video, 0, 0);
}
</script>
http://miernicki.com/cam.html如果你是有興趣看到演示在行動... – 2012-01-19 21:56:29