Media Stream API

User grants access to stream device media, usually either camera and/or microphone.

Uses

  • Use with WebRTC for voice and video calls
  • Picking up on users ambient sound
  • Camera applications

Example

// FYI vendor prefixes are still needed
if (navigator.getUserMedia) {
  // Media Stream Supported
  navigator.getUserMedia(
    {audio: true, video: true},
    function(stream) {
      videoElement.src = window.URL.createObjectURL(stream);
    },
    function(error) {
      videoElement.src = 'myvideosource.webm';
    });
} else {
  // No support
  console.warn('Sorry media stream not supported');
}