Skip to content
Advertisement

How can I use navigator.getMedia in Angular

I have a problem when implementing navigator.getMedia in angular. Which would be the correct way?.

JavaScript

the error is “Property ‘getMedia’ does not exist on type ‘Navigator'”

Advertisement

Answer

Correct syntax would be navigator.MediaDevices.getUserMedia

The MediaDevices.getUserMedia() method prompts the user for permission to use a media input which produces a MediaStream with tracks containing the requested types of media.

That stream can include, for example, a video track (produced by either a hardware or virtual video source such as a camera, video recording device, screen sharing service, and so forth), an audio track (similarly, produced by a physical or virtual audio source like a microphone, A/D converter, or the like), and possibly other track types.

It returns a Promise that resolves to a MediaStream object. If the user denies permission, or matching media is not available, then the promise is rejected with NotAllowedError or NotFoundError DOMException respectively.

https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia

https://developer.chrome.com/blog/media-devices/#getusermedia

JavaScript

Working example: https://stackblitz.com/edit/media-recorder-ukdruh?file=src%2Fapp%2Fapp.component.ts

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement