MediaRecorder
(stream, config)
Audio Recorder with MediaRecorder API.
parameter | type | description |
---|---|---|
stream |
MediaStream | The audio stream to record. |
config |
any
= null
|
navigator.mediaDevices.getUserMedia({ audio: true }).then(stream => {
let recorder = new MediaRecorder(stream)
})
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. |
boolean
:
true
on
audio/wav
and
audio/mpeg
MIME type.
notSupported
()
true
if MediaRecorder can not be polyfilled in the current browser.
Type: boolean
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
MediaRecorder.prototype.mimeType = 'audio/ogg'
MediaRecorder.encoder = oggEncoder
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.
|
undefined
:
recordButton.addEventListener('click', () => {
recorder.start()
})
stop
()
Stop media capture and raise dataavailable
event with recorded data.
undefined
:
finishButton.addEventListener('click', () => {
recorder.stop()
})
pause
()
Pauses recording of media streams.
undefined
:
pauseButton.addEventListener('click', () => {
recorder.pause()
})
resume
()
Resumes media recording when it has been previously paused.
undefined
:
resumeButton.addEventListener('click', () => {
recorder.resume()
})
requestData
()
Raise a dataavailable
event containing the captured media.
undefined
:
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. |
undefined
:
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
.
|
undefined
:
dispatchEvent
(args, event)
Calls each of the listeners registered for a given event.
parameter | type | description |
---|---|---|
args |
...any | |
event |
Event | The event object. |
boolean
:
Is event was no canceled by any listener.
mimeType
()
The MIME type that is being used for recording.
Type: string