如何在 iOS 版 Chrome 中使用 getUserMedia
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29160819/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to use getUserMedia in Chrome for iOS
提问by Rao
I am developing a simple application, in this I am trying to access camera and microphone using getUserMedia
. Its working fine for me in desktop Chrome and Android Chrome but it's not working in iPhone and iPad Chrome.
我正在开发一个简单的应用程序,在此我尝试使用getUserMedia
. 它在桌面 Chrome 和 Android Chrome 中对我来说工作正常,但在 iPhone 和 iPad Chrome 中不起作用。
navigator.getUserMedia = navigator.getUserMedia
|| navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia;
var constraints = "";
if (mediaType === "audio,video") {
constraints = {
audio : true,
video : true
};
} else {
constraints = {
audio : true,
video : false
};
}
navigator.getUserMedia(constraints, successCallback, errorCallback);
回答by wpp
... but it's not working in iPhone and iPad Chrome.
...但它不适用于 iPhone 和 iPad Chrome。
The chrome app on your iPhone or iPad is not running "a full" version of chrome. It's capabilities are limited to the iOS platform. So getUserMedia
and the like probably won't be available until Safari/Apple supports it.
iPhone 或 iPad 上的 chrome 应用程序没有运行“完整”版本的 chrome。它的功能仅限于 iOS 平台。因此getUserMedia
,在Safari/Apple 支持之前,它可能无法使用。
Quoting from another question:
Apple policy forces other browser to use their version of webkit which does not support webRTC, so you will not have webRTC support in a web app on iOS anytime soon. Activity in webkit hints as a change, but time for this to land, it will be months.
Apple 政策强制其他浏览器使用不支持 webRTC 的 webkit 版本,因此您很快将无法在 iOS 上的网络应用程序中获得 webRTC 支持。webkit 中的 Activity 暗示了一个变化,但要让它落地,还需要几个月的时间。
回答by jesup
My understanding (I'm a Mozilla engineer) is that Chrome on iOS doesn't support webrtc or getUserMedia thus far.
我的理解(我是 Mozilla 工程师)是 iOS 上的 Chrome 到目前为止不支持 webrtc 或 getUserMedia。
回答by Jonny
Since "navigator.getUserMedia" is deprecated you should use "navigator.mediaDevices.getUserMedia". This seems (still) to be a problem. Camera access on iOS 11.4 works fine as long as you are using it inside Safari. If you want to use it in any other browser (Chrome, Firefox) it is not supported. Here is an exmaple you can try out:
由于“navigator.getUserMedia”已被弃用,您应该使用“navigator.mediaDevices.getUserMedia”。这似乎(仍然)是一个问题。只要您在 Safari 中使用它,iOS 11.4 上的相机访问就可以正常工作。如果您想在任何其他浏览器(Chrome、Firefox)中使用它,则不支持它。这是您可以尝试的示例:
if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
var constraints = {
audio: true,
video: true
};
navigator.mediaDevices.getUserMedia(constraints)
.then(function(stream) {
var video = document.querySelector('video');
video.srcObject = stream;
video.onloadedmetadata = function(e) {
video.play();
};
})
.catch(function(err) {
console.log (err);
});
}
else {
console.log ("navigator.mediaDevices not supported")
}
<video id="video" width="200" height="200" autoplay playsinline></video>
This code works fine on any desktop device, on Android mobile devices and on iPhone Mobile devices in Safari but just not in Chrome/Firefox: will jump to else case right away: "navigator.mediaDevices not supported"
这段代码适用于任何桌面设备、Android 移动设备和 iPhone 移动设备上的 Safari,但不适用于 Chrome/Firefox:将立即跳转到其他情况:“navigator.mediaDevices not supported”
Since iOS 11.x supports WebRTC I'm not sure where the problem is situated now: Apple or Google/Mozilla? Furthermore if any other working solution is around I'm glad to hear about it.
由于 iOS 11.x 支持 WebRTC,我不确定现在问题出在哪里:Apple 还是 Google/Mozilla?此外,如果有任何其他可行的解决方案,我很高兴听到它。
回答by Kerry Davis
UPDATE: I know this is a very old thread, but as of IOS 11.4 beta,
更新:我知道这是一个非常古老的线程,但从 IOS 11.4 测试版开始,
- getUserMedia is supported but not in PWA (aka standalone aka mobile web app capable) apps 2 FFTSize is now up to 32768 for an analyzer node HOWEVER, there seems to be no way to feed raw live audio into the analyzer node (so roughly the top half of the frequencies are attenuated GREATLY going into the FFT node and forget about installing your own FFT because it will do no better GIGO)
- Latest Desktop Safari seems to be 11.1 and it is even worse since FFTSize tops out at 2048 and you still don't get a raw audio feed.
- getUserMedia 受支持,但在 PWA(又名独立,又名移动网络应用程序)应用程序中不受支持 2 FFTSize 现在对于分析器节点高达 32768,但是,似乎无法将原始实时音频输入分析器节点(大致是顶部)一半的频率在进入 FFT 节点时被大大衰减,而忘记安装自己的 FFT,因为它不会做更好的 GIGO)
- 最新的桌面 Safari 似乎是 11.1 并且更糟,因为 FFTSize 在 2048 时达到顶峰并且您仍然没有获得原始音频馈送。
I keep hoping!
我一直希望!
回答by jlchereau
WebRTC (incl. getUserMedia) is due with iOS11 but will use h264/h265 codecs, i.e. no VP8/VP9.
WebRTC(包括 getUserMedia)适用于 iOS11,但将使用 h264/h265 编解码器,即没有 VP8/VP9。