| Reference | Downloads | Github

TypeError: audioObject.pause() undefined online

URL of experiment: Sign in · GitLab

Description of the problem: As far as I can tell, the audioObject.pause() method does not work on Pavlovia. Here is the error message I get:

Screen Shot 2020-05-05 at 5.39.45 PM

The experiment currently uses sound_1.stop(), which works, but the audio restarts on every next trial. I’d like the audio to pause at the end of a trial, then resume wherever it left off (i.e., for the next trial with sound).

Does anyone know how to get audioObject.pause() working online?

Does anyone know a workaround for this?

.pause() works with sound in Builder, but not online.

How about where you have set pausePos=t at the point you stop the sound?

Best wishes


I tinkered with but I think .seek() only works with MovieStim. I also tried doing a manual JS translation for making .pause() work online, but I was unsuccessful. I also don’t know JS well enough.

Any other ideas?

In case anyone needs this, I’ve figured out a workaround to the .pasue() issue. I still can’t “pause” sound, but I can get the experiment to at least play different parts of an audio file for multiple trials. One of the issues for me was that I could only play the first 5 seconds of a song on multiple trials (i.e., because .stop() resets the audio file to the beginning.

  1. I used GarageBand to clip my ~5 minute audio into 5 second increments.
  2. I added each .wav file to a mySounds column in an Excel file.
  3. I created a trials loop to include the Excel file and set trials to random.
  4. I created a Sound Component with time set to 0.0 and duration blank.
  5. I used a Code Component to end the sound and trial.

Now, instead of only playing the first 5 seconds of the audio file on every trial, a random 5 second .wav file is chosen and played. This isn’t ideal, but fortunately I do not need the audio to play in sequence, from beginning to end. Also, I did try setting the trials loop to sequential, but it repeatedly selects the first 5 seconds of the audio on each trial.

In sum, I used a conditions file to play different parts of a song on each trial.

Hopefully .pause() will be added to psychoJS so that we can use code components to play and pause audio for a sequential stream on multiple trials.