AudioStreamPlayer isn't working

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Mxt08

Hi,
For a game, I need to play multiple sounds and musics. But I don’t know why, it doesn’t play the music, I tried with different wav files changing the settings in the node inspector, but it doesn’t work neither in normal player, nor in the 3D player.
Someone can tell my how I can fix this error?
Thanks in advanced.

AudioStreamPlayer or AudioStreamPlayer2D?
Please give more info. how does your tree look, where and how do you call play?

whiteshampoo | 2021-03-31 16:32

I tried it in AudioStreamPlayer and in AudioStreamPlayer3D, but in two cases it doesn’t work.

Mxt08 | 2021-03-31 17:49

Is your stream empty?
Can you play the sound(.wav) file in the editor?
double click the sound file in the [file system] and it should open in the [inspector].
There’s a [play] and [stop] button, a [spectrogram] and [duration] on the bottom of the inspector. See if you can play the sound file.
Sometimes .wav files exported from Audacity 2.1.0 doesn’t export properly.

bloodsign | 2021-04-01 03:45

Aside from the above, can you give us exactly why you are using the sound. For example, walking sound etc. Because there is a case where your audio stream player constantly play to the point of you’re not hearing it

Mrpaolosarino | 2021-04-01 13:08

:bust_in_silhouette: Reply From: Firty

PaAu is a AudioStreamPlayer

PaAu.stream = loadfile(Url the music)

func loadfile(filepath):
	file.open(filepath, File.READ)
	var bytes = file.get_buffer(file.get_len())
	if filepath.ends_with(".mp3"):
		var newstream = AudioStreamMP3.new()
		newstream.loop = false
		newstream.data = bytes
		return newstream
	else:
		print ("ERROR: Wrong filetype or format")
	file.close()

just call PaAu.play()