Skip to content

Commit

Permalink
add default mimeType if none is specified
Browse files Browse the repository at this point in the history
  • Loading branch information
jadeddelta committed Jan 31, 2025
1 parent 81612ff commit 1f53582
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/sixty-ears-tan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"jspsych": patch
---

add a default `mimeType` of `"video/webm" to `initializeCameraRecorder()`
3 changes: 1 addition & 2 deletions docs/reference/jspsych-pluginAPI.md
Original file line number Diff line number Diff line change
Expand Up @@ -507,8 +507,7 @@ None.

#### Description

Generates a `MediaRecorder` object from provided `MediaStream` and stores this for access via [`getCameraRecorder()`](#getcamerarecorder).

Generates a `MediaRecorder` object from provided `MediaStream` and stores this for access via [`getCameraRecorder()`](#getcamerarecorder). By default, `mimeType` is set to `"video/webm"`.
#### Example

```javascript
Expand Down
5 changes: 4 additions & 1 deletion examples/extension-record-video.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
const jsPsych = initJsPsych({
extensions: [
{type: jsPsychExtensionRecordVideo}
]
],
on_finish: function() {
jsPsych.data.displayData();
}
});

const initCamera = {
Expand Down
6 changes: 6 additions & 0 deletions packages/jspsych/src/modules/plugin-api/MediaAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,12 @@ export class MediaAPI {
private camera_recorder: MediaRecorder = null;

initializeCameraRecorder(stream: MediaStream, opts?: MediaRecorderOptions) {
if (!opts) {
opts = { mimeType: "video/webm" };
} else if (!opts.mimeType) {
opts.mimeType = "video/webm";
}

this.camera_stream = stream;
const recorder = new MediaRecorder(stream, opts);
this.camera_recorder = recorder;
Expand Down

0 comments on commit 1f53582

Please sign in to comment.