Languages
[Edit]
EN

React - play web camera on video element (custom WebCamera component)

3 points
Created by:
Anisha-Kidd
652

In this short article, you can see how in React create custom web camera component using video element and stream video to it.

Example preview:

Example camera streaming to video element using React
Example camera streaming to video element using React

Practical example

Edit

In this example, we present how to create reusable WebCamera component to which we can pass the following properties:

  • width - WebCamera component width in px (equals to video width),
  • height - WebCamera component height in px (equals to video height),
  • onReady - function to be executed once the WebCamera component is ready,
  • onError - function to be executed when some error occurs.

Note:

It is important to be sure the web camera is connected properly, permissions for camera are granted and it is not used by any other application.

 

It is possible to configure audio and video constraints manually by:

 

Giving premissions

Edit

When a web camera is accessed from React you should see notification to permit using it. Just let use it by desired website and remove permissions when it is not needed.

Giving permissions to use web camera under Google Chrome web browser.
Giving permissions to use web camera under Google Chrome web browser.

See also

Edit
  1. JavaScript - play web camera on video element

References

Edit
  1. MediaDevices - MDN Docs
  2. MediaDevices.getUserMedia() - MDN Docs

  3. HTMLMediaElement.srcObject - MDN Docs

  4. <video>: The Video Embed element - MDN Docs

Alternative titles

  1. React - stream web camera to video element
  2. React - web camera own components
  3. React - web camera custom components
  4. React - webcam own components
  5. React - webcam custom components
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join