The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

0 votes

Basically, I want to use my audio stream like how you would use a sprite sheet, except it's filled with assorted sounds rather than sprites. How do I make it play/trim it to only play a single part (in editor I mean, not actually trimming the file so I can reuse it in the future), rather than the whole thing? Thanks in advance!

Godot version 3.2.2
in Engine by (118 points)

1 Answer

+1 vote
Best answer

You can pass an argument to play ( float from_position=0.0 )

Which allows you to play form the position.
Then you could use get_playback_position ( ) and then flag the audio player to stop when it reaches that desired duration.

Pseudo code:

export var start = 10.0
export var end = 20.0
onready var asp = $AudioStreamPlayer

func some_func():
  if !asp.playing:
    asp.play(start)
  if asp.get_playback_position() >= end:
    asp.stop()

PS. I didn't test this code snippet so take it with a grain of coffee and salt
You could also use seek() to set the position of where the audio would start playing.

Check the docs here for more info about Audio:
https://docs.godotengine.org/en/stable/classes/class_audiostreamplayer.html

by (378 points)
selected by

Thanks! I didn't know those functions existed!

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 Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.