October 26, 2022 at 12:34 pm #9626
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):
Thank you very much for your help.
-JinyoungOctober 26, 2022 at 1:19 pm #9627
As you found out, the problem with the command
disableis 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 no
callbackcommand on the Audio element that you could use after
waitto execute some commands after later playbacks
So one solution is to use another element’s
callbackcommand to execute some code that will run in parallel to the main script, which still needs to be running
waiton 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")
JeremyOctober 29, 2022 at 4:38 pm #9646
With your codes, it works perfectly as intended. Thank you so much!
-JinyoungNovember 23, 2022 at 2:56 pm #9733nianpoParticipant
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!
NianpoNovember 29, 2022 at 6:26 pm #9746
Just add a second
newAudio("audio", variable.audio).center().print().wait(), newTimer("callback",1).callback( getAudio("audio").wait().wait().remove() ).start()
JeremyJanuary 21, 2023 at 9:22 pm #9852
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):
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 #9854
Remove the Text element in the same callback, and don’t
waitfor it (you cannot
waitfor Text elements):
newTimer("callback",1) .callback( getText("replay").remove() , getAudio("audio").wait().remove() ) .start()
JeremyJanuary 26, 2023 at 12:41 am #9861
Thanks 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 #9863
My bad, the code should have been
newTimer("callback",1) .callback( getAudio("audio").wait().remove() , getText("replay").remove() ) .start()
February 2, 2023 at 10:39 am #9871
- This reply was modified 9 months, 4 weeks ago by Jeremy. Reason: fix order
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 #9881
Oops, 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
JeremyFebruary 3, 2023 at 10:10 am #9883
This works perfectly, thanks so much!!
- You must be logged in to reply to this topic.