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 loads the sound buffer before Stimulus starts playing the sound buffer. It also 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 Event is fired. This Task Event either starts or stops playback. If a playback is started by pressing the SlideButton, the PlaySoundLoopEvent is fired, thus firing LoopSoundOut1 5000ms later (the sound file is 5000ms long so this is why the number is chosen). LoopSoundOut1 plays the sound again after 5000ms and repeats the process by firing PlaySoundLoopEvent until the user stops playback by pressing the SlideButton again.
NOTE: The audio file in the .zip folder needs to be at the same level as the .es3.
Please sign in to leave a comment.