Audio Seek functionality missing?

Is there an equivalent to a seek() functionality or setting the current time to perform a seek operation within a Babylonjs sound?

I read through the docs, google’d around, and asked OpenAI (which hilariously thought the ‘setPosition()’ was used for this functionality and not for setting a Vector3 for the spatial audio position).

Any advice?

@docEdub might have an idea ?

For sounds that don’t have the streaming option set to true, the first argument to the Sound.play function is the time to seek to before starting.

See Sound.play | Babylon.js Documentation (babylonjs.com).

Note that time argument is currently ignored when the sound is created with the streaming option. We can implement this on streamed sounds, but it is not straight-forward, so let me know if you need this and we can look into it adding it.

@docEdub
Gotcha, so if I wanted to seek a currently playing non-streamed sound, then the recommended path is to dispose of the existing sound object and recreate it with the updated time value we should seek() to?

You don’t need to dispose the sound object. You can just stop it and call play again with the time argument set to the desired seek time.

3 Likes

@docEdub Awesome, thanks!

1 Like

@docEdub Hi, I tried out the suggestion of stopping and then playing the Babylonjs sound with the updated time to start playback at, but the result I’m seeing is that the audio file always restarts playback at currentTime of 0.

I made a playground to show off the potential bug. Did I misinterpret your instructions or is there an incompatibility with the audio file I’m not aware of?

I think this is a bug. I’m looking at it now.

Fixed in PR 13373. Thank you for reporting it.

2 Likes