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

Unable to switch to rear camera even after using facingMode as environment (On Android mobiles) #325

Open
ankush-maherwal opened this issue Mar 18, 2021 · 5 comments

Comments

@ankush-maherwal
Copy link

No description provided.

@ankush-maherwal ankush-maherwal changed the title Unable to switch to rear camera even after using facingMode as environment Unable to switch to rear camera even after using facingMode as environment (On Android mobiles) Mar 18, 2021
@ikeliec
Copy link

ikeliec commented Jun 14, 2021

Hello, what have you tried.? Can you share some codes.

@ankush-maherwal
Copy link
Author

ankush-maherwal commented Jun 15, 2021

@ikeliec For android devices, I had used the following steps to provide switch camera functionality

  1. Add a button to switch / toggle the camera

  2. Onclick of button reset the camera using the reset method
    Webcam.reset();

  3. Re-Initialise the camera
    `

     cameraFacingMode = (cameraFacingMode == 'user') ? 'environment' : 'user';
    
     Webcam.set({
     	width: 50,
     	height: 50,
     	flip_horiz: true,
     	image_format: 'jpeg',
     	jpeg_quality: 100,
     	constraints: {
     		facingMode: cameraFacingMode
     	}
     });
    

`

  1. Attach camera to the div

Webcam.attach('#capture_img');

@ikeliec
Copy link

ikeliec commented Jun 24, 2021

Awesome! @ankush-maherwal . It worked...

Thanks! Gracias!! I appreciate.

@hungpham-cb
Copy link

@ikeliec For android devices, I had used the following steps to provide switch camera functionality

  1. Add a button to switch / toggle the camera
  2. Onclick of button reset the camera using the reset method
    Webcam.reset();
  3. Re-Initialise the camera
    `
     cameraFacingMode = (cameraFacingMode == 'user') ? 'environment' : 'user';
    
     Webcam.set({
     	width: 50,
     	height: 50,
     	flip_horiz: true,
     	image_format: 'jpeg',
     	jpeg_quality: 100,
     	constraints: {
     		facingMode: cameraFacingMode
     	}
     });
    

`

  1. Attach camera to the div

Webcam.attach('#capture_img');

Doesn't work for me, I checked the source code and there's no parameter for facingMode or cameraFacingMode. Should I add it into the source code first?

@hungpham-cb
Copy link

Awesome! @ankush-maherwal . It worked...

Thanks! Gracias!! I appreciate.

Can you show your code how it works? I couldn't get it to flip on my phone browser

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

3 participants