# TypeError: audioObject.pause() undefined online

**URL:** <https://discourse.psychopy.org/t/typeerror-audioobject-pause-undefined-online/13054>\
**Category:** Online experiments\
**Tags:** sound, pavlovia\
**Created:** [May 6, 2020, 4:41am UTC](https://discourse.psychopy.org/t/typeerror-audioobject-pause-undefined-online/13054 "2020-05-06T04:41:14Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![kenny\_j](https://avatars.discourse-cdn.com/v4/letter/k/9fc348/32.png) [@kenny\_j](https://discourse.psychopy.org/u/kenny_j)\
**Post date:** [May 6, 2020, 4:41am UTC](https://discourse.psychopy.org/t/typeerror-audioobject-pause-undefined-online/13054/1 "2020-05-06T04:41:14Z")

</div>

URL of experiment: [Sign in · GitLab](https://gitlab.pavlovia.org/kennethj/reciprocal-schedules)

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](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/f/0/f022e258285f58bf9ff6c7f4112df1e6ae88a90b.png)

The experiment currently uses `sound_1.stop()`, which works, but the audio restarts on every next `sound_1.play()` 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?

---

<div class="post-metadata">

**Author:** ![kenny\_j](https://avatars.discourse-cdn.com/v4/letter/k/9fc348/32.png) [@kenny\_j](https://discourse.psychopy.org/u/kenny_j)\
**Post date:** [May 24, 2020, 1:14am UTC](https://discourse.psychopy.org/t/typeerror-audioobject-pause-undefined-online/13054/2 "2020-05-24T01:14:25Z")

</div>

Does anyone know a workaround for this?

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

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [May 24, 2020, 5:17am UTC](https://discourse.psychopy.org/t/typeerror-audioobject-pause-undefined-online/13054/3 "2020-05-24T05:17:58Z")

</div>

> [@kenny\_j](#):
>
> `sound_1.play()` t

How about `sound_1.seek(pausePos)` where you have set pausePos=t at the point you stop the sound?

Best wishes

Wakefield

---

<div class="post-metadata">

**Author:** ![kenny\_j](https://avatars.discourse-cdn.com/v4/letter/k/9fc348/32.png) [@kenny\_j](https://discourse.psychopy.org/u/kenny_j)\
**Post date:** [May 25, 2020, 12:42am UTC](https://discourse.psychopy.org/t/typeerror-audioobject-pause-undefined-online/13054/4 "2020-05-25T00:42:00Z")

</div>

I tinkered with `sound_1.seek()` 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?

---

<div class="post-metadata">

**Author:** ![kenny\_j](https://avatars.discourse-cdn.com/v4/letter/k/9fc348/32.png) [@kenny\_j](https://discourse.psychopy.org/u/kenny_j)\
**Post date:** [May 26, 2020, 5:04am UTC](https://discourse.psychopy.org/t/typeerror-audioobject-pause-undefined-online/13054/5 "2020-05-26T05:04:14Z")

</div>

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.
