detecting support for getUserMedia on Android browser fails

左心房为你撑大大i 提交于 2019-12-12 21:47:40

问题


I have a problem when detecting support for getUserMedia. I am using Android 4.2.2.

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");           
    }

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.


回答1:


GetUseMedia is not supported in Android Browsers.

http://caniuse.com/stream

getUserMedia(constraints, successCallBack, errorCallBack)

In errorCallBack, check for the error you are getting. You should get the exact reason every time.




回答2:


WebRTC ability is available on Android. It is dependant on if the application has:

  1. The right user permissions
  2. The user has clicked yes to said permission pop ups
  3. The ChromeWebView was instantiated after the above
  4. The ChromeWebView onPermissionRequest has been overrided to allow camera access

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

Please see the following for more information: NotReadableError: Could not start source



来源:https://stackoverflow.com/questions/18358031/detecting-support-for-getusermedia-on-android-browser-fails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!