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 (112 points)

1 Answer

0 votes

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 (334 points)
edited 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 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 webmaster@godotengine.org with your username.