mdn / samples-server

MDN samples server; used for samples that can't be hosted in-place on MDN, plus back-end server-side code for samples that need it.
https://developer.mozilla.org/
Creative Commons Zero v1.0 Universal
956 stars 927 forks source link

Is there a way for this video stream to work on iOS? #94

Open sehsarah opened 4 years ago

sehsarah commented 4 years ago

This example -

https://developer.mozilla.org/en-US/docs/Web/API/WebRTC_API/Taking_still_photos https://mdn-samples.mozilla.org/s/webrtc-capturestill/

On iOS Safari, you open the example, it prompts for webcam use, you allow, then it takes a single frame and stays that way, doesn't open a video stream

Do you have more information on this and whether there's potential for this same webpage to work on iOS somehow?

Thank you! :)

weigangd commented 4 years ago

Hi,

I had the same problem and stumpled upon this. A solution that worked for me was:

  1. Make sure your website is called via HTTPS. (else you need to activate the options in the safari developer tools that WebRTC is allowed on 'unsafe' websites)
  2. Set the "playsinline"-attribute of the video object to true:
navigator.mediaDevices.getUserMedia({video: true, audio: false})
     .then(function(stream) {
        video.srcObject = stream;
        video.setAttribute("playsinline", true);  // <-- this is the important line
        video.play();
    })

Hope it helps!

sehsarah commented 4 years ago

This worked! Thanks so much @Nako11 💯

Should you make a Pull Request for this to be added to the example in this repo? Unsure what the etiquette is to close this Issue or leave it open so others can find it easily.

Thanks so cool!!! 🎉

weigangd commented 4 years ago

Glad it helped :)

I don't know the etiquette either but I created a pull request and maybe @a2sheppy will see it.

I think you should leave this Issue open until the fix is merged.