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:

  1. 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.

  1. Set the {{domxref("MediaRecorder.state")}} to "inactive" and stop capturing media.
  2. Raise a dataavailable event containing the Blob of data that has been

gathered.

  1. Raise a stop event.

Syntax

js-nolint
stop()

Parameters

None.

Return value

None ({{jsxref("undefined")}}).

Exceptions

  • InvalidStateError {{domxref("DOMException")}}
  • : Thrown if the MediaRecorder is 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")}}