问题描述
我在检测对 getUserMedia 的支持时遇到问题.我使用的是 Android 4.2.2.
I have a problem when detecting support for getUserMedia.I am using Android 4.2.2.
问题是android浏览器好像支持getUserMedia,但是在使用它时,我既没有调用success函数,也没有调用fail函数.代码如下:
The problem is that the android browser acts as if it have support for getUserMedia but when using it, I neither get a call to the success function nor the fail function.Code below:
function onCameraFail(e){
alert("Failed getting media");
}
if (navigator.webkitGetUserMedia) {
alert("getMedia supported");
navigator.webkitGetUserMedia({video:true}, function (stream) {
alert("Got media");
}, onCameraFail);
alert("after getMedia");
}else{
//Old device, no support for providing a photo
alert("No support for getUserMedia");
}
在 Android 浏览器上,此代码显示弹出窗口支持 getUserMedia",但我从未收到任何显示获取媒体"或获取媒体失败"的弹出窗口.在 Android 上的 Chrome 中运行相同的代码时,它显示不支持 getUserMedia"
When on Android browser, this code shows the popup "getUserMedia supported" but I never get any popup that says "Got media" or "Failed getting media".When running the same code in Chrome on Android, it says "No support for getUserMedia"
为什么会有这种行为?我认为这是检查功能支持的常用方法.
Why this behavior? I thought that this was the common way to check for support of functions.
推荐答案
WebRTC 功能可在 Android 上使用.这取决于应用程序是否具有:
WebRTC ability is available on Android. It is dependant on if the application has:
- 正确的用户权限
- 用户已单击是"以显示权限弹出窗口
- ChromeWebView 在上述之后被实例化
- ChromeWebView onPermissionRequest 已被覆盖以允许访问相机
您应该在 JavaScript 中获得适当的错误消息(在调用 getUserMedia 时)以了解失败的位置,例如NotReadableError 突出显示权限/无法启动视频源.始终使用适配器以获得一致的错误消息:https://webrtc.github.io/adapter/adapter-latest.js
You should get the appropriate error message (when calling getUserMedia) within JavaScript to know where this fails e.g. NotReadableError highlights permissions/inability to start a video source. Always use the Adapter for consistent error messages: https://webrtc.github.io/adapter/adapter-latest.js
有关详细信息,请参阅以下内容:NotReadableError:无法启动源
Please see the following for more information:NotReadableError: Could not start source
这篇关于在 Android 浏览器上检测对 getUserMedia 的支持失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!