Load should work everywhere, as long you are attempting to open a path that exists and you have read permissions on your system where you are trying to load from. I am no expert of the Audiostreamplayer classes, but it might just be how you are using that class.
You need to load the sounds into the stream then play them once they are loaded. I believe that you can only have one file loaded per AudioStreamPlayer instance, if you change the (music/sound)stream you would have to load another file into the stream. All you have to do once the file is loaded is call the play function on the Audiostreamplayer instance.
You can just created a global class called sounds. Then just added all the sounds as there own AudioStreamPlayer instances to just load them once and add them to sound scene. And make a function to stop and start sounds that exist based on the name. I will post a generalized example of what I mean.
global class sounds.gd
var SoundFileNames: Array
func _init():
func AddSound(var filename)
SoundFileNames.append(filename)
var sound = AudioStreamPlayer.new()
sound.stream = load("user://" + path + filename);
sound.name = filename
add_child(sound)
func SelectSound(sound, state):
var size = SoundFileNames.size()
for n in range(size):
if sound == SoundFileNames[n]:
var soundNode = get_node(sound))
if state == 1:
soundNode.play()
else:
soundNode.stop()
func PlaySound(sound):
SelectSound(sound, 1)
func StopSound(sound):
SelectSound(sound, 0)
From outside of this class you can just call sounds.add(), and .play or .stop for playing or stopping. .
Disclaimers:
After looking at this as well, keep in mind that this doesn't check for duplicate names for filenames, so if that would be an issue you would have to handle the adding and playing of files to handle that.
Also I am not certain if this is the correct way to do this with creating new instances for the audiostreamplayer classes for each sound... this might get bad if you are doing ten-of-thousands of sounds/songs, as I have not tested doing this with beyond like 100 sounds. Hope this leads you to a solution.