Skip to content

Commit 2883e42

Browse files
fix bug with start parameter in video-* plugins - fixes #1806 (#2192)
* fix start param bug in video-* plugins - #1806 * add changeset for video start param fix
1 parent d1fbbd2 commit 2883e42

File tree

4 files changed

+43
-3
lines changed

4 files changed

+43
-3
lines changed

.changeset/violet-steaks-hug.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@jspsych/plugin-video-button-response": patch
3+
"@jspsych/plugin-video-keyboard-response": patch
4+
"@jspsych/plugin-video-slider-response": patch
5+
---
6+
7+
Fix implementation of `start` parameter in `video-*` plugins so that it works in iOS/MacOS browsers.

packages/plugin-video-button-response/src/index.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,13 +236,24 @@ class VideoButtonResponsePlugin implements JsPsychPlugin<Info> {
236236
// before showing and playing, so that the video doesn't automatically show the first frame
237237
if (trial.start !== null) {
238238
video_element.pause();
239-
video_element.currentTime = trial.start;
240239
video_element.onseeked = function () {
241240
video_element.style.visibility = "visible";
241+
video_element.muted = false;
242242
if (trial.autoplay) {
243243
video_element.play();
244+
} else {
245+
video_element.pause();
244246
}
247+
video_element.onseeked = function () {};
248+
};
249+
video_element.onplaying = function () {
250+
video_element.currentTime = trial.start;
251+
video_element.onplaying = function () {};
245252
};
253+
// fix for iOS/MacOS browsers: videos aren't seekable until they start playing, so need to hide/mute, play,
254+
// change current time, then show/unmute
255+
video_element.muted = true;
256+
video_element.play();
246257
}
247258

248259
let stopped = false;

packages/plugin-video-keyboard-response/src/index.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,13 +189,24 @@ class VideoKeyboardResponsePlugin implements JsPsychPlugin<Info> {
189189
// before showing and playing, so that the video doesn't automatically show the first frame
190190
if (trial.start !== null) {
191191
video_element.pause();
192-
video_element.currentTime = trial.start;
193192
video_element.onseeked = function () {
194193
video_element.style.visibility = "visible";
194+
video_element.muted = false;
195195
if (trial.autoplay) {
196196
video_element.play();
197+
} else {
198+
video_element.pause();
197199
}
200+
video_element.onseeked = function () {};
201+
};
202+
video_element.onplaying = function () {
203+
video_element.currentTime = trial.start;
204+
video_element.onplaying = function () {};
198205
};
206+
// fix for iOS/MacOS browsers: videos aren't seekable until they start playing, so need to hide/mute, play,
207+
// change current time, then show/unmute
208+
video_element.muted = true;
209+
video_element.play();
199210
}
200211

201212
let stopped = false;

packages/plugin-video-slider-response/src/index.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,13 +284,24 @@ class VideoSliderResponsePlugin implements JsPsychPlugin<Info> {
284284
// before showing and playing, so that the video doesn't automatically show the first frame
285285
if (trial.start !== null) {
286286
video_element.pause();
287-
video_element.currentTime = trial.start;
288287
video_element.onseeked = function () {
289288
video_element.style.visibility = "visible";
289+
video_element.muted = false;
290290
if (trial.autoplay) {
291291
video_element.play();
292+
} else {
293+
video_element.pause();
292294
}
295+
video_element.onseeked = function () {};
296+
};
297+
video_element.onplaying = function () {
298+
video_element.currentTime = trial.start;
299+
video_element.onplaying = function () {};
293300
};
301+
// fix for iOS/MacOS browsers: videos aren't seekable until they start playing, so need to hide/mute, play,
302+
// change current time, then show/unmute
303+
video_element.muted = true;
304+
video_element.play();
294305
}
295306

296307
let stopped = false;

0 commit comments

Comments
 (0)