MediaRecorder: pause() method
MDN Web Docs · نسخهٔ df622a2a1c1e · CC BY-SA 2.5 و مجوز جداگانهٔ ناشر برای نمونهکد
{{APIRef("MediaStream Recording")}}
The **pause()** method of the {{domxref("MediaRecorder")}} interface is used to pause recording of media streams.
When a MediaRecorder object's pause() method is called, the browser queues a task that runs the below steps:
- If {{domxref("MediaRecorder.state")}} is "inactive", raise a DOM
InvalidState error and terminate these steps. If not, continue to the next step.
- Set {{domxref("MediaRecorder.state")}} to "paused".
- Stop gathering data into the current {{domxref("Blob")}}, but keep it available so
that recording can be resumed later on.
- Raise a {{domxref("MediaRecorder/pause_event", "pause")}} event.
Syntax
js-nolint
pause()Parameters
None.
Return value
None ({{jsxref("undefined")}}).
Exceptions
InvalidStateError{{domxref("DOMException")}}- : Thrown if the
MediaRecorderis currently"inactive"; you cannot pause
the recording if the MediaRecorder is not active. If you call pause() while already paused, the method silently does nothing.
Examples
js
pause.onclick = () => {
mediaRecorder.pause();
console.log("recording paused");
};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")}}