What I want to do is : - select a music file in a folder - set up the audio stream - play the audio stream

The problem that I have is that I can't set-up the audio stream (ask him to play a file from his path)

So how do you set the path to an audio stream "dynamically"

22 days later

hi Benhub, you have various options. 1/ you are loading audio files from res:// (internal and already imported) 2/ from user:// (external but need to be imported first) 3/ from anywhere in your computer using path selection and buffering

  • i am using both of those options and it works, depending of your project

in case you want to fix your code, please, post it here as we can have a look and help you in the process ;)

@uriel said: in case you want to fix your code, please, post it here as we can have a look and help you in the process ;)

Thank you, i have no idea how to buffer sound, here is the code i made to play the sound:

func _on_ButtonDebug_pressed(): $AudioStreamPlayer.resource_path = filePath $AudioStreamPlayer.play()

and the error returned is :

Edit : I looked in the doc and found nothing

Have you seen this tutorial from GameFromScratch? The first snippet of example code shows how to create an AudioStreamPlayer in GDScript. It might help explain how to load audio in GDScript. (I have not seen the tutorial myself, so I’m not totally sure on what it covers)

Looking at the code posted, you need to change $AudioStreamPlayer.resource_path = filePath to $AudioStreamPlayer.stream = load(filePath). That should load the audio file at the file path. :) (Side note: welcome to the forums)

3 years later