MediaRecorderErrorEvent.error - Web APIs 编辑

The read-only error property in the MediaRecorderErrorEvent interface is a DOMException object providing details about the exception that was thrown by a MediaRecorder instance.

When a MediaRecorderErrorEvent occurs, you can determine to some extent what went wrong by examining the error property within the MediaRecorderErrorEvent received by the MediaRecorder's error event handler, onerror.

Syntax

error = MediaRecorderErrorEvent.error;

Value

A DOMException describing the error represented by the event. The error's name property's value may be any exception that makes sense during the handling of media recording, including these specifically identified by the specification. The descriptions here are generic ones; you'll find more specific ones to various scenarios in which they may occur in the corresponding method references.

InvalidStateError
An operation was attempted in a context in which it isn't allowed, or a request has been made on an object that's deleted or removed.
NotSupportedError
A MediaRecorder couldn't be created because the specified options weren't valid. The message atttribute should provide additional information, if it exists.
SecurityError
The 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.
InvalidModificationError
The number of tracks on the stream being recorded has changed. You can't add or remove tracks while recording media.
UnknownError
A non-security related error occurred that cannot otherwise be categorized. Recording stops, the MediaRecorder's state becomes inactive, one last dataavailable event is sent to the MediaRecorder with the remaining received data, and finally a stop event is sent.

Examples

Basic error-handling example

This function creates and returns a MediaRecorder for a given MediaStream, configured to buffer data into an array and to watch for errors.

function recordStream(stream) {
  let recorder = null;
  let bufferList = [];

  try {
    recorder = new MediaRecorder(stream);
  } catch(err) {
    /* exception while trying to create the recorder; handle that */
  }

  recorder.ondataavailable = function(event) {
    bufferList.push(event.data);
  };

  recorder.onerror = function(event) {
    let error = event.error;
  };

  recorder.start(100);  /* 100ms time slices per buffer */
  return recorder;
}

Specifications

SpecificationStatusComment
MediaStream Recording
The definition of 'MediaRecorderErrorEvent.error' in that specification.
Working DraftInitial specification.

Browser compatibility

BCD tables only load in the browser

The compatibility table on 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.

See also

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:62 次

字数:6387

最后编辑:7 年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文