MediaRecorderErrorEvent.error

我们的志愿者还没有将这篇文章翻译为 中文 (简体)加入我们帮助完成翻译
您也可以阅读此文章的English (US)版。

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 Media​Recorder​Error​Event occurs, you can determine to some extent what went wrong by examining the error property within the Media​Recorder​Error​Event 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.

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

Specification Status Comment
MediaStream Recording
The definition of 'MediaRecorderErrorEvent.error' in that specification.
Working Draft Initial specification.

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
errorChrome No support No
Notes
No support No
Notes
Notes Uses a generic event with an error property.
Edge No support NoFirefox Full support 57IE No support NoOpera No support No
Notes
No support No
Notes
Notes Uses a generic event with an error property.
Safari No support NoWebView Android No support NoChrome Android No support No
Notes
No support No
Notes
Notes Uses a generic event with an error property.
Firefox Android Full support 57Opera Android No support No
Notes
No support No
Notes
Notes Uses a generic event with an error property.
Safari iOS No support NoSamsung Internet Android No support No

Legend

Full support  
Full support
No support  
No support
See implementation notes.
See implementation notes.

See also

文档标签和贡献者

此页面的贡献者: Wind1808, mdnwebdocs-bot, fscholz, Sheppy
最后编辑者: Wind1808,