当前位置: 首页 > 工具软件 > mediadevices > 使用案例 >

webRTC的MediaDevices的常用属性,方法,事件

松英叡
2023-12-01

MediaDevices 接口提供访问连接媒体输入的设备,如照相机和麦克风,以及屏幕共享等。它可以使你取得任何硬件资源的媒体数据。

属性

从父类EventTarget中继承的属性.

事件

方法

从其父项继承方法 EventTarget.

示例

'use strict';

// Put variables in global scope to make them available to the browser console.
var video = document.querySelector('video');
var constraints = window.constraints = {
  audio: false,
  video: true
};
var errorElement = document.querySelector('#errorMsg');

navigator.mediaDevices.getUserMedia(constraints)
.then(function(stream) {
  var videoTracks = stream.getVideoTracks();
  console.log('Got stream with constraints:', constraints);
  console.log('Using video device: ' + videoTracks[0].label);
  stream.onended = function() {
    console.log('Stream ended');
  };
  window.stream = stream; // make variable available to browser console
  video.srcObject = stream;
})
.catch(function(error) {
  if (error.name === 'ConstraintNotSatisfiedError') {
    errorMsg('The resolution ' + constraints.video.width.exact + 'x' +
        constraints.video.width.exact + ' px is not supported by your device.');
  } else if (error.name === 'PermissionDeniedError') {
    errorMsg('Permissions have not been granted to use your camera and ' +
      'microphone, you need to allow the page access to your devices in ' +
      'order for the demo to work.');
  }
  errorMsg('getUserMedia error: ' + error.name, error);
});

function errorMsg(msg, error) {
  errorElement.innerHTML += '<p>' + msg + '</p>';
  if (typeof error !== 'undefined') {
    console.error(error);
  }
}

规范

规范状态评论
Media Capture and Streams MediaDevicesCandidate Recommendation初始定义

浏览器兼容性

desktopmobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariWebView AndroidChrome AndroidFirefox AndroidOpera AndroidiOS SafariSamsung Internet
MediaDevicesFull support47Full support12Full support33No supportNoFull support30Full support11Full support47Full support47Full support36Full support30Full support11Full support5.0
devicechange eventFull support57Full support12Full support52No supportNoFull support34Full support11No supportNoNo supportNoCompatibility unknown; please update this.?Full support43Full support11No supportNo
enumerateDevicesFull support47Full support12Full support39OpenNo supportNoFull support34Full support11Full support47Full support47Full support39OpenFull support34Full support11Full support5.0
getDisplayMedia()Full support72OpenFull support79OpenFull support66OpenNo supportNoFull support60OpenFull support13No supportNofootnoteOpenNo supportNoNo supportNofootnoteOpenNo supportNoNo supportNoNo supportNo
Audio capture supportFull support74footnoteOpenFull support≤ 79footnoteOpenNo supportNoNo supportNoCompatibility unknown; please update this.?No supportNoNo supportNoNo supportNoNo supportNoNo supportNoNo supportNoNo supportNo
getSupportedConstraintsFull support53Full support12Full support44No supportNoFull support40Full support11Full support53Full support52Full support50Full support41Full support11Full support6.0
getUserMediaFull support53footnoteOpenFull support12Full support36footnoteOpenNo supportNoFull support40footnoteOpenFull support11Full support53Full support53footnoteOpenFull support36footnoteOpenFull support41footnoteOpenFull support11Full support6.0
Secure context requiredFull support53Full support79Full support68No supportNoFull support40Compatibility unknown; please update this.?Full support53Full support53Full support68Full support41Compatibility unknown; please update this.?Full support6.0
ondevicechangeFull support57Full support12Full support52OpenNo supportNoFull support34Full support11No supportNoNo supportNoFull supportYesFull support34Full support11No supportNo
Stereo audio captureCompatibility unknown; please update this.?Compatibility unknown; please update this.?Full support55No supportNoCompatibility unknown; please update this.?No supportNoCompatibility unknown; please update this.?Compatibility unknown; please update this.?No supportNoCompatibility unknown; please update this.?No supportNoCompatibility unknown; please update this.?

 类似资料: