MediaRecorder 方法 start() , which is part of the MediaStream Recording API, begins recording media into one or more Blob 对象。 You can record the entire duration of the media into a single Blob (or until you call requestData() ), or you can specify the number of milliseconds to record at a time. Then, each time that amount of media has been recorded, an event will be delivered to let you act upon the recorded media, while a new Blob is created to record the next slice of the media

Assuming the MediaRecorder 's state is inactive , start() 设置 state to recording , then begins capturing media from the input stream. A Blob is created and the data is collected in it until the time slice period elapses or the source media ends. Each time a Blob is filled up to that point (the timeslice duration or the end-of-media, if no slice duration was provided), a dataavailable event is sent to the MediaRecorder with the recorded data. If the source is still playing, a new Blob is created and recording continues into that, and so forth.

When the source stream ends, state 被设为 inactive and data gathering stops. A final dataavailable event is sent to the MediaRecorder , followed by a stop 事件。

注意 : If the browser is unable to start recording or continue recording, it 将引发 DOMError event, followed by a MediaRecorder.dataavailable event containing the Blob it has gathered, followed by the MediaRecorder.stop 事件。

句法

mediaRecorder.start(timeslice)
					

参数

timeslice 可选
The number of milliseconds to record into each Blob . If this parameter isn't included, the entire media duration is recorded into a single Blob 除非 requestData() method is called to obtain the Blob and trigger the creation of a new Blob into which the media continues to be recorded.

返回值

undefined .

异常

Errors that can be detected immediately are thrown as DOM exceptions. All other errors are reported through error events sent to the MediaRecorder object. You can implement the onerror event handler to respond to these errors.

InvalidModificationError

The number of tracks on the stream being recorded has changed. You can't add or remove tracks while recording media.

InvalidStateError
MediaRecorder is not in the inactive state; you can't start recording media if it's already being recorded. See the state 特性。
NotSupportedError

The media stream you're attempting to record is inactive, or one or more of the stream's tracks is in a format that can't be recorded using the current configuration.

SecurityError
MediaStream is configured to disallow recording. This may be the case, for example, with sources obtained using getUserMedia() when the user denies permission to use an input device.  This also happens when a MediaStreamTrack within the stream is marked as isolated due to the peerIdentity constraint on the source stream. This exception may also be delivered as an error event if the security options for the source media change after recording begins.
UnknownError

Something else went wrong during the recording process.

范例

...
  record.onclick = function() {
    mediaRecorder.start();
    console.log("recorder started");
  }
...
					

规范

规范 状态 注释
MediaStream 录制
The definition of 'MediaRecorder.start()' in that specification.
工作草案 初始定义

浏览器兼容性

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
start 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

图例

完整支持

完整支持

不支持

不支持

另请参阅

元数据

  • 最后修改: