0 votes

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

asked Feb 8 in Engine by ufukbakan (20 points)

1 Answer

+1 vote
Best answer

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.

answered Feb 8 by jgodfrey (5,248 points)
selected Feb 9 by ufukbakan

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
....

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

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:

https://docs.godotengine.org/en/latest/classes/class_audiostreamplayer.html

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.

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

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.