How to get set AudioStreamPlayer duration

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By ufukbakan

How to get/set AudioStreamPlayer current duration? im using mono (c#) version but you can answer using gdscript

:bust_in_silhouette: Reply From: jgodfrey

So, you’re looking for the length of the AudioStream that your AudioStreamPlayer is currently playing?

If so, in GDScript that’d be…

$AudioStreamPlayer.stream.get_length()

If, instead, you’re looking for the time remaining in the currently playing stream, I guess you could get that with a combination of the above (the total duration) and this:

$AudioStreamPlayer.get_playback_position() which returns the current time into playing track.

I want to skip first 39 seconds after first loop
I have a audio file which is 58 seconds so i want to do:
1st loop : 58 seconds
2nd loop: 58 minus 39 seconds
3rd looop: 58 minus 39 seconds

ufukbakan | 2020-02-08 23:53

You mentioned only getters if there is no setters this is a shame

ufukbakan | 2020-02-09 00:13

Well, you don’t have to guess about what is and is not available. You can just check the docs. For AudioStreamPlayer, that’s here:

AudioStreamPlayer — Godot Engine (latest) documentation in English

There, you can see there’s a seek function that’ll allow you to set the position in the AudioStream.

Additionally, there’s a finished signal you could use to tell when the stream finishes.

Those things, used together, should give you all the functionality necessary to do what you describe, I think.

jgodfrey | 2020-02-09 00:40

Thanks for documentation i connected finished signal to function play :
void play ( float from_position=0.0 )
Plays the audio from the given from_position, in seconds.

ufukbakan | 2020-02-09 14:23