The MediaRecorder.start() method (part of the MediaRecorder API) is used to start capturing media into a 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.stopevent.
Note: If the browser is unable to start recording or continue recording, it will raise a DOMError event, followed by a MediaRecorder.dataavailable event containing the Blob it has gathered, followed by the MediaRecorder.stop event.
Syntax
MediaRecorder.start(timeslice)
Parameters
- timesliceOptional
- This parameter takes a value of milliseconds, and represents the length of media capture to return in each Blob. If it is not specified, all media captured will be returned in a single Blob, unless one or more calls are made to MediaRecorder.requestData.
Errors
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.
Example
...
  record.onclick = function() {
    mediaRecorder.start();
    console.log("recorder started");
  }
...
Specifications
| Specification | Status | Comment | 
|---|---|---|
| MediaStream Recording The definition of 'MediaRecorder.start()' in that specification. | Working Draft | Initial definition | 
Browser compatibility
| Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) | 
|---|---|---|---|---|---|
| Basic support | 47 | 25.0 (25.0) | No support | No support | No support | 
| Feature | Android | Android Webview | Firefox Mobile (Gecko) | Firefox OS | IE Phone | Opera Mobile | Safari Mobile | Chrome for Android | 
|---|---|---|---|---|---|---|---|---|
| Basic support | No support | 47 | 25.0 (25.0) | 1.3[1] | No support | No support | No support | 47 | 
[1] The intial Firefox OS implementation only supported audio recording.
See also
- Using the MediaRecorder API
- Web Dictaphone: MediaRecorder + getUserMedia + Web Audio API visualization demo, by Chris Mills (source on Github.)
- simpl.info MediaStream Recording demo, by Sam Dutton.
- Navigator.getUserMedia
Document Tags and Contributors
    
    Tags: 
    
  
                    
                       Contributors to this page: 
        miguelao, 
        Sebastianz, 
        jpmedley, 
        chrisdavidmills, 
        teoli, 
        tenorioming@yahoo.com, 
        kscarfone
                    
                    
                       Last updated by:
                      miguelao,