[英]How do I access navigator.getUserMedia()?
I am currently running Chrome 11 and trying to access getUserMedia
for HTML5 native audio and video stream support but I am getting an error saying that navigator.getUserMedia
is undefined. 我目前正在运行Chrome 11并尝试访问getUserMedia
以获取HTML5本机音频和视频流支持,但我收到一条错误消息,指出navigator.getUserMedia
未定义。 If it's not supported, how do I access it or do I need to wait until Chrome incorporates it? 如果它不受支持,我该如何访问它,还是需要等到Chrome合并它?
This is the the code I was using to test getUserMedia
which I found 这是我用来测试我发现的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>
Since last night (3 May 2012) getUserMedia() in Chrome Canary takes an object not a string. 自昨晚(2012年5月3日)以来,Chrome Canary中的getUserMedia()获取的对象不是字符串。
To try it out, you can run the following code from the console on any page (like this one ) with a video element: 要试用它,您可以使用视频元素在任何页面( 如此页面)上从控制台运行以下代码:
navigator.webkitGetUserMedia(
{"video": true, "audio": true},
function(s){
document.querySelector('video').src =
window.webkitURL.createObjectURL(s);
},
function(e){console.log(e);}
);
The latest opera desktop build has support for getUserMedia() See here: http://labs.opera.com/news/2011/10/19/ 最新的opera桌面版本支持getUserMedia()请访问: http : //labs.opera.com/news/2011/10/19/
It's just a waiting game for other browsers to implement this. 这只是其他浏览器实现这一目标的等待游戏。 Now that opera has support, the other should soon follow. 现在歌剧有了支持,另一个应该很快就会出现。
I think there is a stub method in the latest chrome dev (12.0.742.16 dev) but i can't get it to do anything on Mac OSX. 我认为在最新的chrome dev(12.0.742.16 dev)中有一个存根方法,但我无法在Mac OSX上做任何事情。 At least I thought I saw it. 至少我以为我看到了它。 I just checked and the method doesn't seem to be there anymore. 我刚检查过,方法似乎不再存在了。 Here is the webkit bug report for implementing getUserMedia: https://bugs.webkit.org/show_bug.cgi?id=56586 以下是用于实现getUserMedia的webkit错误报告: https ://bugs.webkit.org/show_bug.cgi ? id = 56586
I think the only working implementation at the moment is in Opera for Android. 我认为目前唯一可行的实现是Opera for Android。 http://my.opera.com/core/blog/2011/03/23/webcam-orientation-preview http://my.opera.com/core/blog/2011/03/23/webcam-orientation-preview
The chrome/webkit method is webkitGetUserMedia but it isn't implemented yet. chrome / webkit方法是webkitGetUserMedia,但尚未实现。
Chrome Dev Channel JUST added WebRTC support, so NOW what you're asking here actually becomes plausible. Chrome Dev Channel刚刚添加了WebRTC支持,所以现在你在这里问的实际上变得合情合理。 See: https://groups.google.com/forum/#!topic/discuss-webrtc/LuY7zYLA8sA 请参阅: https : //groups.google.com/forum/#!topic/discuss-webrtc/LuY7zYLA8sA
Basically, you must use the webkit prefixe: webkitGetUserMedia() although documentation on this method is scarce, I'm currently trying to piece together a working demo of it. 基本上,你必须使用webkit前缀:webkitGetUserMedia()虽然这个方法的文档很少,但我正在尝试拼凑它的工作演示。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.