mirror of
https://github.com/jspsych/jsPsych.git
synced 2025-05-10 11:10:54 +00:00
implement compatible mimetype searching if no mimetype provided
This commit is contained in:
parent
1f535826a2
commit
d258a29aae
@ -284,17 +284,38 @@ export class MediaAPI {
|
|||||||
private camera_recorder: MediaRecorder = null;
|
private camera_recorder: MediaRecorder = null;
|
||||||
|
|
||||||
initializeCameraRecorder(stream: MediaStream, opts?: MediaRecorderOptions) {
|
initializeCameraRecorder(stream: MediaStream, opts?: MediaRecorderOptions) {
|
||||||
if (!opts) {
|
let mimeType = this.getCompatibleMimeType() || "video/webm";
|
||||||
opts = { mimeType: "video/webm" };
|
const recorderOptions: MediaRecorderOptions = {
|
||||||
} else if (!opts.mimeType) {
|
...opts,
|
||||||
opts.mimeType = "video/webm";
|
mimeType
|
||||||
}
|
}
|
||||||
|
|
||||||
this.camera_stream = stream;
|
this.camera_stream = stream;
|
||||||
const recorder = new MediaRecorder(stream, opts);
|
const recorder = new MediaRecorder(stream, recorderOptions);
|
||||||
this.camera_recorder = recorder;
|
this.camera_recorder = recorder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// mimetype checking code adapted from https://github.com/lookit/lookit-jspsych/blob/develop/packages/record/src/videoConfig.ts#L673-L699
|
||||||
|
/** returns a compatible mimetype string, or null if none from the array are supported. */
|
||||||
|
private getCompatibleMimeType(): string {
|
||||||
|
const types = [
|
||||||
|
// chrome firefox edge
|
||||||
|
"video/webm;codecs=vp9,opus",
|
||||||
|
"video/webm;codecs=vp8,opus",
|
||||||
|
// general
|
||||||
|
'video/mp4; codecs="avc1.42E01E, mp4a.40.2"',
|
||||||
|
// safari
|
||||||
|
"video/mp4;codecs=h264,aac",
|
||||||
|
"video/mp4;codecs=hevc,aac",
|
||||||
|
]
|
||||||
|
for (const mimeType of types) {
|
||||||
|
if (MediaRecorder.isTypeSupported(mimeType)) {
|
||||||
|
return mimeType;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
getCameraStream(): MediaStream {
|
getCameraStream(): MediaStream {
|
||||||
return this.camera_stream;
|
return this.camera_stream;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user