MediaRecorder: error event
The MediaRecorder
interface's error
event is fired when an error occurs: for example because recording wasn't allowed or was attempted using an unsupported codec.
Bubbles | No |
---|---|
Cancelable | No |
Interface | MediaRecorderErrorEvent |
Event handler property | onerror |
For details of the all the possible errors see the documentation for the event handler property: onerror
.
Examples
Using addEventListener
to listen for error
events:
async function record() {
const stream = await navigator.mediaDevices.getUserMedia({audio: true});
const recorder = new MediaRecorder(stream);
recorder.addEventListener('error', (event) => {
console.error(`error recording stream: ${event.error.name}`)
});
recorder.start();
}
record();
The same, but using the onerror event handler property:
async function record() {
const stream = await navigator.mediaDevices.getUserMedia({audio: true});
const recorder = new MediaRecorder(stream);
recorder.onerror = (event) => {
console.error(`error recording stream: ${event.error.name}`)
};
recorder.start();
}
record();
Specifications
Specification | Status |
---|---|
MediaStream Recording | Working Draft |
Browser compatibility
BCD tables only load in the browser