23

Apple released a statement that getUserMedia will be fully functional on iOS 11. After installing iOS 11 Beta version 5, I do get a message that my website requests access to my camera and microphone, but it seems that the line:

video.src = window.URL.createObjectURL(stream);

or:

video.srcObject = stream;

Does not work. No errors, no exceptions, simply no picture from the phone's camera.

Here's my full script:

$(function () {
     video = document.getElementById('vid');

     navigator.getUserMedia = navigator.getUserMedia ||
                              navigator.webkitGetUserMedia ||
                              navigator.mozGetUserMedia;

     navigator.getUserMedia(
     {
         audio: true,
         video: { facingMode: "user" }
     }, function (stream) {
         video.srcObject = stream;
         //video.src = window.URL.createObjectURL(stream);
     },
     function (err) {           
         alert(err.name);
     });
});

HTML:

<video id="vid" muted autoplay></video>

Has anyone got it working? Any ideas would be appreciated.

1 Answer 1

26

Solved it by using the following:

$(function () {
    video = document.getElementById('vid');
    video.style.width = document.width + 'px';
    video.style.height = document.height + 'px';
    video.setAttribute('autoplay', '');
    video.setAttribute('muted', '');
    video.setAttribute('playsinline', '');

    var constraints = {
         audio: false,
         video: {
             facingMode: 'user'
         }
    }

    navigator.mediaDevices.getUserMedia(constraints).then(function success(stream) {
        video.srcObject = stream;
    });
});
8
  • 1
    Yep, it's moved to navigator.mediaDevices. Also note that while video seems to work everywhere, audio doesn't work on iPod touch - asking for audio causes an Overconstrained Error. Oct 2, 2017 at 19:42
  • 1
    I got a black screen in video and I have almost the same code. did you face this problem ? thanks Oct 16, 2017 at 21:28
  • 10
    SOLVED black screen : <video id="videoforsaf" autoplay playsinline></video> Oct 16, 2017 at 21:44
  • I'm keep getting same issue like described here: stackoverflow.com/questions/46981889/… Although I'm running iOS11.1 Nov 14, 2017 at 17:44
  • @IvanPandžić I'll be happy to help if you post a new question with your code and link it to me here as a comment. Voting up my question and asnwer would be appreciated too :)
    – Koby Douek
    Nov 14, 2017 at 18:18

Not the answer you're looking for? Browse other questions tagged or ask your own question.