Content Deep Dive
Choosing cameras in JavaScript with the mediaDevices API
Blog post from Twilio
Post Details
Company
Date Published
Author
Phil Nash
Word Count
1,780
Language
English
Hacker News Points
-
Summary
You can choose between two cameras, select one based on its ID, and switch between them. The mediaDevices API allows you to access the camera's video stream and enumerate all available devices for both audio and video input. You can also use the facingMode constraint to select a front-facing or rear-facing camera on mobile devices. To switch between cameras, retain a reference to the current stream and stop it when switching to another one. The mediaDevices API provides a way to influence which camera is selected by using constraints such as facingMode or deviceId.