Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replay button should be present even after audio prompt stops playing #192

Merged
merged 5 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion task-launcher/src/tasks/shared/helpers/PageStateHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ export class PageStateHandler {
audioUri: string;
audioBuffer?: AudioBuffer;
replayBtn: HTMLButtonElement;
playStimulusOnLoad: boolean;

constructor(audioFile: string) {
constructor(audioFile: string, playStimulusOnLoad: boolean) {
this.audioFile = audioFile;
this.audioUri = mediaAssets.audio[camelize(this.audioFile)] ||
mediaAssets.audio.nullAudio;
this.getbuffer();
this.replayBtn = document.getElementById('replay-btn-revisited') as HTMLButtonElement;
this.playStimulusOnLoad = playStimulusOnLoad !== undefined ? playStimulusOnLoad : true;
}

async getbuffer() {
Expand Down
16 changes: 9 additions & 7 deletions task-launcher/src/tasks/shared/helpers/replayAudio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import { PageStateHandler } from "./PageStateHandler";

export async function setupReplayAudio(pageStateHandler: PageStateHandler) {
if (pageStateHandler.replayBtn) {
pageStateHandler.disableReplayBtn();
const enableDelayBuffer = 100; //in ms
const totalStimulusDurationMs = await pageStateHandler.getStimulusDurationMs(); //in ms
const totalDelay = totalStimulusDurationMs + enableDelayBuffer;
setTimeout(() => {
pageStateHandler.enableReplayBtn();
}, totalDelay);
if (pageStateHandler.playStimulusOnLoad){
pageStateHandler.disableReplayBtn();
const enableDelayBuffer = 100; //in ms
const totalStimulusDurationMs = await pageStateHandler.getStimulusDurationMs(); //in ms
const totalDelay = totalStimulusDurationMs + enableDelayBuffer;
setTimeout(() => {
pageStateHandler.enableReplayBtn();
}, totalDelay);
}

const onAudioEnd = () => {
pageStateHandler.enableReplayBtn();
Expand Down
17 changes: 9 additions & 8 deletions task-launcher/src/tasks/shared/trials/afcStimulus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ function getStimulus(layoutConfigMap: Record<string, LayoutConfigType>) {
}
}


const getPromptTemplate = (
prompt: string,
mediaSrc: string | null,
Expand All @@ -122,13 +123,12 @@ const getPromptTemplate = (
stimulusContainerClassList: string[],
) => {
let template = '<div class="lev-stimulus-container">';
if (!noAudio) {
template += `
<button id="${replayButtonHtmlId}" class="replay">
${replayButtonSvg}
</button>
`;
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this function no longer uses the noAudio so that can be removed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot about that, thanks!

template += `
<button id="${replayButtonHtmlId}" class="replay">
${replayButtonSvg}
</button>
`;

if (prompt) {
template += `
Expand Down Expand Up @@ -323,7 +323,8 @@ function doOnLoad(layoutConfigMap: Record<string, LayoutConfigType>) {

const stim = taskStore().nextStimulus;
const itemLayoutConfig = layoutConfigMap?.[stim.itemId];
const pageStateHandler = new PageStateHandler(stim.audioFile);
const noAudio = layoutConfigMap?.[stim.itemId].noAudio;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can just do itemLayoutConfig?.noAudio here.

const pageStateHandler = new PageStateHandler(stim.audioFile, !noAudio);
const isPracticeTrial = stim.assessmentStage === 'practice_response';
const isInstructionTrial = stim.trialType === 'instructions';
// Handle the staggered buttons
Expand Down
Loading