MediaRecorder: stop() method
MDN Web Docs · نسخهٔ df622a2a1c1e · CC BY-SA 2.5 و مجوز جداگانهٔ ناشر برای نمونهکد
{{APIRef("MediaStream Recording")}}
The **stop()** method of the {{domxref("MediaRecorder")}} interface is used to stop media capture.
When the stop() method is invoked, the UA queues a task that runs the following steps:
- If {{domxref("MediaRecorder.state")}} is "inactive", raise a DOM
InvalidState error and terminate these steps. If the {{domxref("MediaRecorder.state")}} is not "inactive", continue on to the next step.
- Set the {{domxref("MediaRecorder.state")}} to "inactive" and stop capturing media.
- Raise a
dataavailableevent containing the Blob of data that has been
gathered.
- Raise a
stopevent.
Syntax
js-nolint
stop()Parameters
None.
Return value
None ({{jsxref("undefined")}}).
Exceptions
InvalidStateError{{domxref("DOMException")}}- : Thrown if the
MediaRecorderis currently"inactive"; you cannot stop
the recording if the MediaRecorder is not active.
Examples
js
stop.onclick = () => {
mediaRecorder.stop();
console.log("recorder stopped, data available");
};Specifications
{{Specifications}}
Browser compatibility
{{Compat}}
See also
- Using the MediaStream Recording API
- Web Dictaphone: MediaRecorder +
getUserMedia + Web Audio API visualization demo, by Chris Mills (source on GitHub.)
- simpl.info MediaStream Recording demo, by Sam Dutton.
- {{domxref("Navigator.getUserMedia")}}