This article applies to:
This experiment illustrates how to loop a sound based on whether a SlideButton is clicked.
In the experiment, the Init InLine runs the InitLoopTaskEvent subroutine. This creates a dummy Task Event to execute the LoopSoundOut1 subroutine after 5000ms when called (i.e. when PlaySoundLoopEvent is fired, LoopSoundOut1 will run after 5000ms).
On the Stimulus Slide, a SlideButton is presented. When the SlideButton is clicked, the PlaySoundOut1 Task Events is fired. This Task Event either starts or stops playback. If a playback is started and the PlaySoundLoopEvent is fired, meaning that LoopSoundOut1 will fire after 5000ms (the sound file is 500ms long so this is why the number is chosen).
LoopSoundOut1 plays the sound again after 5000ms and repeats the process by firing PlaySoundLoopEvent.
NOTE: The audio file in the .zip folder needs to be at the same level as the .es3.