MediaRecorder() 构造函数创建新 MediaRecorder object that will record a specified MediaStream . The object can optionally be configured to record using a specific media container (file type), and, further, can specify the exact codec and codec configuration(s) to use by specifying the codecs 参数 .

句法

var mediaRecorder = new MediaRecorder(stream[, options]);
					

参数

stream
MediaStream that will be recorded. This source media can come from a stream created using navigator.mediaDevices.getUserMedia() or from an <audio> , <video> or <canvas> 元素。

选项 可选

A dictionary object that can contain the following properties:

  • mimeType : A MIME type specifying the format for the resulting media; you may simply specify the container format (the browser will select its preferred codecs for audio and/or video), or you may 使用 codecs 参数 and/or the profiles parameter to provide detailed information about which codecs to use and how to configure them. Applications can check in advance if a mimeType is supported by the 用户代理 通过调用 MediaRecorder.isTypeSupported() .
  • audioBitsPerSecond : The chosen bitrate for the audio component of the media.
  • videoBitsPerSecond : The chosen bitrate for the video component of the media.
  • bitsPerSecond : The chosen bitrate for the audio and video components of the media. This can be specified instead of the above two properties. If this is specified along with one or the other of the above properties, this will be used for the one that isn't specified.

If bits per second values are not specified for video and/or audio, the default adopted for video is 2.5Mbps, while the audio default is adaptive, depending upon the sample rate and the number of channels.

异常

NotSupportedError

The specified MIME type is not supported by the user agent.

范例

This example shows how to create a media recorder for a specified stream, whose audio bit rate is set to 128 Kbit/sec and whose video bit rate is set to 2.5 Mbit/sec. The recorded media data will be stored in an MP4 wrapper (so if you gather the chunks of media data and save them to disk, they will be in an MP4 file).

...
if (navigator.mediaDevices.getUserMedia) {
  var constraints = { audio: true, video: true };
  var chunks = [];
  var onSuccess = function(stream) {
    var options = {
      audioBitsPerSecond : 128000,
      videoBitsPerSecond : 2500000,
      mimeType : 'video/mp4'
    }
    var mediaRecorder = new MediaRecorder(stream,options);
    m = mediaRecorder;
...
  }
}
					

规范

规范 状态 注释
MediaStream 录制 工作草案 初始定义

浏览器兼容性

The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
MediaRecorder() 构造函数 Chrome 47 Edge 79 Firefox 25 IE No Opera 36 Safari No WebView Android 47 Chrome Android 47 Firefox Android 25 Opera Android 36 Safari iOS No Samsung Internet Android 5.0
选项 对象 Chrome 49 Edge 79 Firefox 43 IE No Opera 36 Safari No WebView Android 49 Chrome Android 49 Firefox Android ? Opera Android 36 Safari iOS No Samsung Internet Android 5.0

图例

完整支持

完整支持

不支持

不支持

兼容性未知 ?

兼容性未知

另请参阅

元数据

  • 最后修改: