Hi, for the soundtrack of my game I use 3 loopable tracks, and when the current playing track is 3 seconds from the end I fade out/in to the next track.
Is there a way to know the current playing position for a sound playing, and a way to check the length of the sound?
Alternatively, would tracking the playing position using Update be a reasonable workaround?
This is currently not possible, see issues:
opened 09:07AM - 26 Jul 23 UTC
feature request
engine
sound
I would like to be able to get and set the timeline positions of sounds in Defol… d.
Use case:
We have three intensity variations of a music track. At certain points in the track, we check if we want to switch to another intensity level. The variations are **not** mapped 1:1 in terms of duration and position, so for example if we're at 00:12 of one track we might want to switch to 00:23 for the other.
For get, I would expect something like:
```
go.get("#sound", "timeline_position")
```
You could do a workaround for the get side by tracking time elapsed since you started the track. I've tried this before, but do not find it to be a reliable solution. I can not think of a workaround for the set side.
For set, I would expect something like:
```
go.set("#sound", "timeline_position", 23.7)
```
However, for my use case it would also be acceptable if the timeline position is set on play (similar to the [offset parameter in sprite.play_flipbook](https://defold.com/ref/stable/sprite/#sprite.play_flipbook:url-id-[complete_function]-[play_properties])).
I've looked around for similar functions elsewhere: FMOD ([get](https://documentation.help/FMOD-Studio-API/FMOD_Channel_GetPosition.html) / [set](https://documentation.help/FMOD-Studio-API/FMOD_Channel_SetPosition.html)), Unity ([both](https://docs.unity3d.com/ScriptReference/AudioSource-time.html)), Godot (seemingly only [get](https://docs.godotengine.org/en/3.3/classes/class_audiostreamplayer.html#class-audiostreamplayer-method-get-playback-position))
opened 10:34AM - 23 May 19 UTC
feature request
engine
sound
This feature has been requested with the aim to sync content with music.
E.g.… at certain times (bytes/milliseconds or something) during a music track, the post effects could change, particle effects could spawn etc...
Highly recommend going and upvoting those issues.
A hacky solution is to keep track of the time through update, just like you said. Disabling threaded audio might improve reliability of that hack but would potentially hurt performance.
1 Like
Highly recommend going and upvoting those issues.
Will do. Thanks. Implemented the hack and seems to work!
1 Like