PennController for IBEX › Forums › Support › Audio replay only once
- This topic has 11 replies, 3 voices, and was last updated 1 year, 10 months ago by project.travel.
-
AuthorPosts
-
October 26, 2022 at 12:34 pm #9626project.travelParticipant
Hello,
I’d like to build a trial where the participants play an audio by clicking the button, see the images (which appear right after the audio is played), optionally play the audio once more (but only one additional time, not more) and choose one of the two images. In the current version of our experiment, the audio is played when I click the play button but it seems that hitting the space bar after that replays the audio however many times I’d like to play. I’ve tried using disable() but was not able to get the right design of the trial. How do I block unlimited replays, and allow replaying just once?
Here is the link to the experiment (You can look at “target_A” trial, although all trials use the same format):
https://farm.pcibex.net/r/wMBIZT/
Thank you very much for your help.
-Jinyoung
October 26, 2022 at 1:19 pm #9627JeremyKeymasterHello Jinyoung,
As you found out, the problem with the command
disable
is that it doesn’t prevent the participant from playing the audio again by simply pressing the spacebar (which is something I should fix). Another problem is there’s nocallback
command on the Audio element that you could use afterwait
to execute some commands after later playbacksSo one solution is to use another element’s
callback
command to execute some code that will run in parallel to the main script, which still needs to be runningwait
on the Selector element:newAudio("audio", variable.audio).center().print().wait(), newTimer("callback",1).callback( getAudio("audio").wait().remove() ).start()
This way, if the participant plays the Audio element again, it will simply disappear from the page
Now, another problem with your script is you print a Canvas element at the center of the page that you scale to fit the page’s dimensions, which results in that Canvas element covering the other elements already on the page, notably the Audio element, which you can no longer click because clicks now target the Canvas element on top of it instead. You should probably rethink the way you display the different elements (eg. by printing everything, including the texts and the Audio element inside the Canvas element) but if you want to keep things how they currently are, a straightforward solution is to make the clicks on the Canvas element “transparent”:
newCanvas("canvas", 1800, 1000) .add(200, 380, getImage("nrc") ) .add(1000, 380, getImage("rrc") ) .scaling("page") .print("center at 50vw", "middle at 50vh") .cssContainer("pointer-events", "none")
Jeremy
October 29, 2022 at 4:38 pm #9646project.travelParticipantHi Jeremy,
With your codes, it works perfectly as intended. Thank you so much!
-Jinyoung
November 23, 2022 at 2:56 pm #9733nianpoParticipantHi Jeremy,
Thank you for your detailed reply all the time!
I am wondering how to make audio replay only twice. That is, participants can replay the audio once or twice, based on their own needs. Do you know how should I modify the codes? Many thanks!
Best wishes,
NianpoNovember 29, 2022 at 6:26 pm #9746JeremyKeymasterHi Nianpo,
Just add a second
.wait
:newAudio("audio", variable.audio).center().print().wait(), newTimer("callback",1).callback( getAudio("audio").wait().wait().remove() ).start()
Jeremy
January 21, 2023 at 9:22 pm #9852project.travelParticipantHi again,
I have a similar question as before in my experiment https://farm.pcibex.net/r/wMBIZT/.
I’d like a text (defined as “replay”) to appear after the audio is played for the first time, and make it disappear after the replay. (The text means ‘you can play it once more.’) As you can see in my demo link, I tried the following and a few others (in the “practice” trial):
newTimer(“callback”,1)
.callback(getAudio(“audio”).wait().remove())
.callback(getText(“replay”).wait().remove())
.start()The text doesn’t disappear afther the second audio play, though. Maybe I’m not understanding how the newTimer and the callback works here.
Thank you for your help!
January 22, 2023 at 3:03 pm #9854JeremyKeymasterHi,
Remove the Text element in the same callback, and don’t
wait
for it (you cannotwait
for Text elements):newTimer("callback",1) .callback( getText("replay").remove() , getAudio("audio").wait().remove() ) .start()
Jeremy
January 26, 2023 at 12:41 am #9861project.travelParticipantThanks for the response!
Just to follow up on your suggestion, I tried the new code, but the text now no longer appears on the page. Is there a way to make the text (“You can play it once more”) show up but disappears *after* the participant has replayed the audio?
Thank you in advance for your help!
January 30, 2023 at 6:11 pm #9863JeremyKeymasterHi,
My bad, the code should have been
newTimer("callback",1) .callback( getAudio("audio").wait().remove() , getText("replay").remove() ) .start()
Jeremy
- This reply was modified 1 year, 10 months ago by Jeremy. Reason: fix order
February 2, 2023 at 10:39 am #9871project.travelParticipantHi Jeremy,
Sorry, I think this is the same code as the previous one you posted. Is there a missing component in this line?
Thanks again!
February 3, 2023 at 9:32 am #9881JeremyKeymasterOops, I copied and pasted the code from my previous message but completely forgot to edit it!
I’ve updated my message, the commands are now in the appropriate order
Apologies
JeremyFebruary 3, 2023 at 10:10 am #9883project.travelParticipantHi Jeremy,
This works perfectly, thanks so much!!
Best,
Sanghee -
AuthorPosts
- You must be logged in to reply to this topic.