MediaRecorder (stream, config)

Audio Recorder with MediaRecorder API.

parameter type description
stream MediaStream The audio stream to record.
config any = null

Examples

navigator.mediaDevices.getUserMedia({ audio: true }).then(stream => {
  let recorder = new MediaRecorder(stream)
})

Static Members

isTypeSupported (mimeType)

Returns true if the MIME type specified is one the polyfill can record.

This polyfill supports audio/wav and audio/mpeg.

parameter type description
mimeType string The mimeType to check.

Returns

boolean : true on audio/wav and audio/mpeg MIME type.

notSupported ()

true if MediaRecorder can not be polyfilled in the current browser.

Type: boolean

Examples

if (MediaRecorder.notSupported) {
  showWarning('Audio recording is not supported in this browser')
}

encoder ()

Converts RAW audio buffer to compressed audio files. It will be loaded to Web Worker. By default, WAVE encoder will be used.

Type: function

Examples

MediaRecorder.prototype.mimeType = 'audio/ogg'
MediaRecorder.encoder = oggEncoder

Instance Members

stream ()

The MediaStream passed into the constructor.

Type: MediaStream

state ()

The current state of recording process.

Type: ("inactive" | "recording" | "paused")

start (timeslice?)

Begins recording media.

parameter type description
timeslice number? The milliseconds to record into each Blob . If this parameter isn’t included, single Blob will be recorded.

Returns

undefined :

Examples

recordButton.addEventListener('click', () => {
  recorder.start()
})

stop ()

Stop media capture and raise dataavailable event with recorded data.

Returns

undefined :

Examples

finishButton.addEventListener('click', () => {
  recorder.stop()
})

pause ()

Pauses recording of media streams.

Returns

undefined :

Examples

pauseButton.addEventListener('click', () => {
  recorder.pause()
})

resume ()

Resumes media recording when it has been previously paused.

Returns

undefined :

Examples

resumeButton.addEventListener('click', () => {
  recorder.resume()
})

requestData ()

Raise a dataavailable event containing the captured media.

Returns

undefined :

Examples

this.on('nextData', () => {
  recorder.requestData()
})

addEventListener (args, type, listener)

Add listener for specified event type.

parameter type description
args ...any
type ("start" | "stop" | "pause" | "resume" | "dataavailable" | "error") Event type.
listener function The listener function.

Returns

undefined :

Examples

recorder.addEventListener('dataavailable', e => {
  audio.src = URL.createObjectURL(e.data)
})

removeEventListener (args, type, listener)

Remove event listener.

parameter type description
args ...any
type ("start" | "stop" | "pause" | "resume" | "dataavailable" | "error") Event type.
listener function The same function used in addEventListener .

Returns

undefined :

dispatchEvent (args, event)

Calls each of the listeners registered for a given event.

parameter type description
args ...any
event Event The event object.

Returns

boolean : Is event was no canceled by any listener.

mimeType ()

The MIME type that is being used for recording.

Type: string