Reply To: Audio replay only once

PennController for IBEX Forums Support Audio replay only once Reply To: Audio replay only once


Hello 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 no callback command on the Audio element that you could use after wait to execute some commands after later playbacks

So 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 running wait on the Selector element:

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") )
    .print("center at 50vw", "middle at 50vh")
    .cssContainer("pointer-events", "none")