detecting support for getUserMedia on Android brow

2019-07-18 06:13发布

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条回答
够拽才男人
2楼-- · 2019-07-18 06:33

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.

查看更多
登录 后发表回答