Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Video Constraints Props Doesn't Work in Mobile Device but Works Fine in Web and Web Responsive Simulator #370

Open
3 tasks done
HzdAngga opened this issue Apr 5, 2023 · 6 comments

Comments

@HzdAngga
Copy link

HzdAngga commented Apr 5, 2023

Please follow the general troubleshooting steps first:

Bug reports:

I tried the videoConstraints with aspect-ratio 9 / 16 in web and responsive simulator in web and it works fine, but when open it in mobile device (android), the resolution of react-webcam video isnt 9 / 16 (back to default resolution of react-webcam). Any ideas how to make it works in mobile device?

Features:

Please note by far the quickest way to get a new feature is to file a Pull Request.

We will consider your request but it may be closed if it's something we're not actively planning to work on.

@Duskfen
Copy link

Duskfen commented Jul 14, 2023

Same for me, but not only with aspect-ratio, but with specifying height and width.

Note that this works on mobile Firefox but not on mobile chrome

@mozmorris

@RehkMansa
Copy link

I'm having this same issue, how did you guys handle this

@Duskfen
Copy link

Duskfen commented Sep 6, 2023

I haven't dealt with it so far, but next thing would be using a different camera library I guess 😞

@RehkMansa
Copy link

What library, I think its not a library thing, but something with the constraints

@Duskfen
Copy link

Duskfen commented Sep 15, 2023

I now fiddled with custom options via the getUserMedia
(f.e. i just executed in the browser inspector

    navigator.mediaDevices
      .getUserMedia({
        audio: false,
        video: {
                aspectRatio: 16 / 9,
                height: { ideal: 1920 },
                frameRate: { ideal: 60 },
          facingMode: 'user',
        },
      })
      .then((mediaStream) => {
        const video = document.querySelector('video');
        video.srcObject = mediaStream;
        video.onloadedMetadata = () => {
          video.play();
        };
      })
      .catch((err) => {
        console.log(`my error: ${err.name}: `, err);
      });

)
And indeed it seems like no library issue but a constraints issue. (Maybe some browsers changed some inner mechanic which then lead to this issue)

In the past we had a full-screen camera dialog, which it seems isn't possible anymore..
the constraints which met our requirements are those stated in the example above.

To find constraints that fit to your usecase i recommend you reading through following links and playing around with the options:

@mcking49
Copy link

I also had the same issue and then realised that it was because the default orientation for desktop was landscape, while mobile was portrait. So in the end I was able to make it work for both platforms by swapping the width and height constraints depending on device type.

For example:

<Webcam
  videoConstraints={{
    height: isMobile
      ? { ideal: 1080, max: 2160, min: 720 }
      : { ideal: 1920, max: 3840, min: 1280 },
    width: isMobile
      ? { ideal: 1920, max: 3840, min: 1280 }
      : { ideal: 1080, max: 2160, min: 720 },
  }}
/>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants