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

support camera select. #310

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

narrowizard
Copy link

@narrowizard narrowizard commented Apr 22, 2020

working in progress

  • flash mode
  • get user media
  • ios
  • documents

@narrowizard narrowizard changed the title [WIP] support camera choose. [WIP] support camera select. Apr 22, 2020
@narrowizard narrowizard marked this pull request as draft April 22, 2020 05:47
@narrowizard narrowizard changed the title [WIP] support camera select. support camera select. Apr 22, 2020
@narrowizard
Copy link
Author

narrowizard commented Apr 23, 2020

notice

  • it is not support for ios platform(for UA /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream).

usage

checkout demos/choose-camera.html

demo

// register init event before `attach`, it will trigger when `getCameras` is valid.
Webcam.on("init", function () {
  Webcam.getCameras(function (cameras) {
    if (cameras.length > 0) {
      Webcam.setAndInitCamera(cameras[cameras.length - 1].id);
    }
  });
});
Webcam.attach("#my_camera", true);

api

// getCameras return all reachable cameras. you should call it after `init` event.
Webcam.getCameras(function(data){ 
  // data is array of camera objects.
  // with id, label
  // id: camera id, you should call setCamera with it
  // label: camera name
});

// setAndInitCamera select camera via id(from getCameras method), and start camera.
Webcam.setAndInitCamera(id);

// initCamera start camera, it will use default camera if camera is not spcified.
// it is useful when you cannot find the camera you want.
Webcam.initCamera();

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

Successfully merging this pull request may close these issues.

1 participant