Pausing and playing an audio with offset restarts it from the beginning instead of the current position

I am trying to pause and play an audio which was started with an offset. Instead of resuming from the position that it was paused, the audio restarts from the beginning. Repro is added in the playground below. The pause/play is done inside the onPointerUpObservable of the Issue button. After pausing and playing, I would expect the audio to resume at around 10 seconds. But instead, the audio restarts from 0 seconds

The issue seems to be coming from this line which doesn’t consider the current offset when assigning the _startOffset and this line which also ignores the offset if isPaused is true.

As a temporary workaround, the below steps work

sound.isPaused = true;, 10)

cc @docEdub (please be aware that many team members are on vacations so response times may be slower)

I know its not ideal, but you can always manually set the startOffset before hitting play again.

        const offset = 10
        sound.stop(), offset)
        sound._startOffset = offset

I was looking at the code and it seems like this line and the above might be the culprit.

@carolhmj it feels like a bug do you want to have a look ? or I can if you prefer ?

I can have a look!

1 Like

I’m looking into this right now.

1 Like

Fixed in PR 13373. Thank you for reporting it.


@docEdub Thanks a lot for the super fast response and fix. The pause / play seems to be working now. However, I now seem to be getting a new issue. When I try to restart an audio by calling play(0, 0) on a sound which has previously been started with an offset, it is not starting from 0 but from the previous offset. The relevant code and playground are added below, 10);
sound.stop();, 0) // I would expect this to start from 0, but it is starting from 10

(Error in onPointerUpObservable)

Is this expected ?

Nope. Sounds like I broke it. I’ll take a look.

Silly mistake on my part. Pull request #13425 fixes it. Thanks again!


Hi, @docEdub I think I might be running into another issue now (v5.42.1). When I try to get the current time of the audio, the return value seems to be different in the two scenarios below

Scenario 1

sound.stop();, 10);
console.log(sound.currentTime) // This gives a non-zero value

Scenario 2

sound.stop();, 10);
console.log(sound.currentTime) // This always returns "0"


Is this behavior expected ?

Thanks again for the quick fixes and releases

1 Like

I don’t know if this is expected or not, but it doesn’t make sense to me that stopping while paused makes currentTime return a different value than stopping while not paused. I would expect the stop function to reset any state related to pause and always reset currentTime to zero.

PR #13444 addresses this.

1 Like

Refreshing to see quick updates on a big repo. Awaiting the next release. Thanks !


@docEdub Apologies for the repeated posts, but I just checked the v5.43.0 release and think I’m getting into another issue. In the latest release, the currentTime after pausing an audio is always returning 0

console.log(sound.currentTime) // Always returns 0


Checked with v5.42.2 on PG and v5.43.0 on local. Is this an expected functionality or a bug?

P.S: I’m adding all issues here since it is easier to follow a single thread of fixes. Please let me know if I should be creating new thread for each issue, I’d be happy to do that.

@docEdub I wonder if we could add tests on this part as well ???