Stream video with getUserMedia()

By | April 13, 2020
Request the user to start their webcam stream
  1. Using the getUserMedia() API which allows you to access a user’s camera and mic without any plugins
  2. Streams have inputs (video) and outputs (video)
  3. The if-conditional checks if the getUserMedia is supported
  4. Syntax: navigator.mediaDevices.getUserMedia(constraints).then(successCallback).catch(errorCallback)
  5. The getUserMedia() method takes one argument called the MediaStreamConstraints object which allows you to specify the constrains/specifications of the media . In this case video is set to true
  6. Media.getUserMedia() returns then method which returns a promise which will take 2 parameter:
  • a callback function which resolves to a media stream object, in this case video
  • failure function for a failure
  1. If there is is an error, or the user refuses to give permission to access the webcam then ‘error’ is logged to the console

Join 7000+ other code newbies

Last year 7000 newbies learned how to code with me! Totally project oriented.

Subscribe and you'll get access to my classes, coupon codes for tech conferences and totally valuable article on jump-starting your career as a developer.

We won't send you spam. Unsubscribe at any time. Powered by ConvertKit

Leave a Reply

Your email address will not be published. Required fields are marked *