Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MediaDevices.getUserMedia() prompts the user for permission then launches camera app on full screen instead of in-browser

I am using getUserMedia() to take images on a vue web app. Working everywhere except on iOS safari. The user is asked permission for accessing the camera, after user accepts the camera is launched on a full screen instead of in-browser. I have to manually close it and then I can see the camera feed in my web app.

Can this be avoided? I want to show the camera feed in the browser where I have some functionality instead of launching the camera on full screen after user confirms permission. I'm guessing this is a iOS-safari issue and not js or chrome..

Basic syntax:

navigator.mediaDevices.getUserMedia(constraints)
.then(function(stream) {
  /* use the stream */
})
.catch(function(err) {
  /* handle the error */
});
like image 523
user10745267 Avatar asked Nov 21 '25 18:11

user10745267


1 Answers

In my case, adding playsinline attribute into element solved the problem.

Working code:

<video
    ref="video"
    autoplay
    playsinline
/>

<script>
    const stream = await navigator.mediaDevices.getUserMedia({
      video: true,
      audio: false,
    })

    this.$refs.video.srcObject = stream
</script>
like image 124
Hung Nguyen Avatar answered Nov 24 '25 06:11

Hung Nguyen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!