23

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.

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);
wpp
  • 7,093
  • 4
  • 33
  • 65
Rao
  • 231
  • 1
  • 2
  • 3
  • 1
    Please clarify: are you writing a Chrome App and deploying it with Mobile Chrome Apps toolchain, or are you building a web app? In the latter case, please fix the tag to [tag:google-chrome] – Xan Mar 20 '15 at 09:20
  • 1
    I am building web app.. – Rao Mar 20 '15 at 11:16

6 Answers6

19

... but it's not working in iPhone and 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.

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.

Community
  • 1
  • 1
wpp
  • 7,093
  • 4
  • 33
  • 65
12

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:

            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"

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.

Jonny
  • 816
  • 10
  • 24
10

My understanding (I'm a Mozilla engineer) is that Chrome on iOS doesn't support webrtc or getUserMedia thus far.

jesup
  • 6,765
  • 27
  • 32
5

As of iOS 14, this changed. Now WKWebView adds support for getUserMedia. @Marcus explains it very well here: https://stackoverflow.com/a/63092094/6931862

TLDR;

WKWebView can use getUserMedia in iOS 14.3 beta 1.

Hermes
  • 2,828
  • 2
  • 14
  • 34
2

UPDATE: I know this is a very old thread, but as of IOS 11.4 beta,

  1. 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)
  2. 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.

I keep hoping!

Kerry Davis
  • 171
  • 1
  • 4
  • 12
0

WebRTC (incl. getUserMedia) is due with iOS11 but will use h264/h265 codecs, i.e. no VP8/VP9.

jlchereau
  • 1,152
  • 1
  • 7
  • 5