mediaRecorder
Provides a cross-browser utility for recording a MediaStream from an HTMLVideoElement.
It uses the native captureStream
on the HTMLVideoElement
iself where available and falls back to
a HTMLCanvasElement
based approach for browsers like iOS Safari that do not support it.
It also automatically selects a supported MIME type for MediaRecorder by checking availability.
Functions¶
createRecordingPromise()¶
Defined in: src/utils/mediaRecorder.ts:100
Creates a promise that resolves with a recorded File object from a MediaStream.
Parameters¶
Parameter | Type | Description |
---|---|---|
stream |
MediaStream |
The stream to record. |
duration |
number |
The duration to record in milliseconds. |
recordingOptions |
{ fileExtension : string ; mimeType : string ; } |
The selected mimeType and extension. |
recordingOptions.fileExtension |
string |
- |
recordingOptions.mimeType |
string |
- |
Returns¶
A promise that resolves with the recorded video file.
getStream()¶
Defined in: src/utils/mediaRecorder.ts:25
Gets a MediaStream from a video element, using a canvas fallback if necessary.
Parameters¶
Parameter | Type | Description |
---|---|---|
videoElement |
HTMLVideoElement |
The video element to get a stream from. |
endTime |
number |
The time when the recording should stop. |
Returns¶
A promise that resolves with the combined media stream.
getSupportedMimeType()¶
Defined in: src/utils/mediaRecorder.ts:159
Iterates through a list of preferred MIME types and returns the first one supported by the browser.
Returns¶
| null
| {
fileExtension
: string
;
mimeType
: string
;
}
The best supported MIME type and corresponding file extension, or null if none are supported.
recordMediaStream()¶
Defined in: src/utils/mediaRecorder.ts:188
Records a clip from a video element between a start and end time. This is the main function to be called from UI components.
Parameters¶
Parameter | Type | Description |
---|---|---|
videoElement |
HTMLVideoElement |
The video element to record from. |
startTime |
number |
The time in seconds to start the recording. |
endTime |
number |
The time in seconds to end the recording. |
Returns¶
A promise that resolves with the recorded video file.