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

Conversation

zwatson2001
Copy link
Collaborator

This PR keeps the replay button on the screen even for trials where the audio prompt is silenced. It also prevents it from being disabled at first using the noAudio parameter stored in layoutConfigMap.

@@ -2,15 +2,17 @@ import { PageAudioHandler } from "./audioHandler";
import { PageStateHandler } from "./PageStateHandler";


export async function setupReplayAudio(pageStateHandler: PageStateHandler) {
export async function setupReplayAudio(pageStateHandler: PageStateHandler, noAudio: boolean = false) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

You have the right approach. I am thinking whether we move this behavior to the PageStateHandler itself. Because the PageStateHandler is responsible for pagestate and setupReplayAudio function just listens to pagestate and decides the audio. Potentially we can do something like this:
In PageStateHandler.tsx:

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;
  }

Initialize the PageStateHandler with the noAudio value like you did for setupReplayAudio

and then in this function:

if (pageStateHandler.replayBtn) {
    if (pageStateHandler.playStimulusOnLoad){
      ... rest of the code
    }

Let me know what you think.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@zwatson2001 does Aritra's comment make sense? I'd like this one merged soon -- thanks!

@asengupta3
Copy link
Collaborator

asengupta3 commented Sep 13, 2024

@kachergis will we ever have a trial where we do not show the replay button at all (like an instruction trial or otherwise)?

@kachergis
Copy link
Collaborator

@asengupta3 there are no current tasks / instructions where we don't want the replay button, although I could imagine a language task where we don't want to allow participants to repeat the stimulus endlessly. (e.g., I don't think ROAR's Phoneme Awareness task allows repetition). Certainly default is to have the replay button.

@asengupta3
Copy link
Collaborator

@asengupta3 there are no current tasks / instructions where we don't want the replay button, although I could imagine a language task where we don't want to allow participants to repeat the stimulus endlessly. (e.g., I don't think ROAR's Phoneme Awareness task allows repetition). Certainly default is to have the replay button.

Okay then maybe we can rename our noAudio config to playAudioOnLoad and use it to determine whether we play the audio at the beginning or not.

@zwatson2001
Copy link
Collaborator Author

@asengupta3 the playAudioOnLoad suggestion makes sense to me - @kachergis should I maybe wait to add that as a second PR so that this one can be merged quickly?

@@ -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.

</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!

@asengupta3
Copy link
Collaborator

@asengupta3 the playAudioOnLoad suggestion makes sense to me - @kachergis should I maybe wait to add that as a second PR so that this one can be merged quickly?

I think that is fine. The rename can wait till next PR.

Copy link
Collaborator

@asengupta3 asengupta3 left a comment

Choose a reason for hiding this comment

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

LGTM!

@zwatson2001 zwatson2001 merged commit 132d6d0 into main Sep 17, 2024
3 checks passed
@asengupta3 asengupta3 deleted the add-replay-button-no-audio branch September 20, 2024 18:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants