MediaRecorder.start()
Метод MediaRecorder.start() (часть MediaRecorder API (en-US)) используется для начала захвата медиа Blob.
When the start() method is invoked, the UA queues a task that runs the following steps:
- If the
MediaRecorder.stateis not "inactive", raise a DOMInvalidStateerror and terminate these steps. if theMediaRecorder.stateis "inactive", continue on to the next step. - Set the
MediaRecorder.stateto "recording" and wait until media becomes available from thestreampassed intoNavigator.getUserMedia. - Once data becomes available, raise a
MediaRecorder.startevent and start gathering the data into aBlob(see FILE-API). - If the
timeSliceargument has been provided, once that many milliseconds of data have been collected — or a minimum time slice imposed by the UA, whichever is greater — raise aMediaRecorder.dataavailableevent containing the Blob of collected data, and start gathering a new Blob of data. IftimeSlicehas not been provided, continue gathering data into the original Blob. - When the
streamis ended, setMediaRecorder.stateto "inactive" and stop gathering data. - Raise a
MediaRecorder.dataavailableevent containing the Blob of data. - Raise a
MediaRecorder.stop(en-US) event.
Примечание: If the browser is unable to start recording or continue recording, it will raise a DOMError (en-US) event, followed by a MediaRecorder.dataavailable event containing the Blob it has gathered, followed by the MediaRecorder.stop (en-US) event.
Синтаксис
MediaRecorder.start(timeslice)
Параметры
timesliceНеобязательный-
Этот параметр принимает значение в миллисекундах, и переопределяет длину куска захвата медиа для возвращения в каждом Blob. Если не указан, то все медиа данные будут занесены в один Blob, только если не был вызван метод
MediaRecorder.requestData.
Ошибки
An InvalidState error is raised if the start() method is called while the MediaRecorder object’s MediaRecorder.state is not "inactive" — it makes no sense to start media capture if it is already happening.
Пример
js
...
record.onclick = function() {
mediaRecorder.start();
console.log("рекордер запущен");
}
...
Specifications
| Specification | Status | Comment |
|---|---|---|
| MediaStream Recording Определение 'MediaRecorder.start()' в этой спецификации. |
Рабочий черновик | Initial definition |
Совместимость с браузерами
BCD tables only load in the browser
Смотрите также
- Использование MediaRecorder API (en-US)
- Веб-диктофон: MediaRecorder + getUserMedia + Web Audio API от Chris Mills (исходники на Github.)
- simpl.info Пример использования MediaStream от Sam Dutton.
Navigator.getUserMedia