Runs without errors, but no sound from AudioStreamPlayer

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

This is my code, in a separate, autoloaded scene.

extends Control

# Load the music player node
onready var _player = $AudioStreamPlayer

# calling this function will load a given tarck, and play it
func play(track_url : String):
#	_player.stop() 
	var track = load(track_url)
	_player.stream = track
	_player.play()
	print(track_url)
	
# Calling this function will stop the track	
func stop():	
	_player.stop()

The print(track_url) gives expected results, so I know the function is being called. No errors are posted, but no sound is played from either .ogg or .wav.

It turns out that I CAN call the music from outside of my game directory if I move the sound file into the game directory, let Godot import it, and then copy the import file into my outside directory that holds the sound file. It’s a bit of a clunky workaround, but I can live with it. I may even be able to automate the process, so when I run the Muse, and add a new sound to my sound collection, I could automatically copy it into my game directory, let the engine reimport it and create the import file, then copy the import file back to my sound collection. Like I said, clunky, but I thrive on adversity! LOL!

Sylkie | 2019-11-27 07:57

:bust_in_silhouette: Reply From: Sylkie

An addendum. If I move the .ogg or .wav into the resource directory, and load it from there, it works. But I need to be able to play music and sounds outside of my resource folder. How can I access sound files that do not live in my app directory?

Comment under your question instead of adding this as an answer.

Dlean Jeans | 2019-11-27 05:26

:bust_in_silhouette: Reply From: Dlean Jeans

Maybe you didn’t add the player to the scene:

func _ready():
    add_child(_player)

A good bet, but no dice. I added the child on ready but still didn’t get it. After all of the research I have done on this, (nearly two days worth of Googling) I have come to the conclusion it is not possible. LOL! It seems you must have imported the sound into the engine before you can play it. Darn shame too, as this is a very polished little piece that could have been quite useful in organizing my sound files. I’m thinking I may just put the source for the project out there for others to use as an example of what can be done… filling listboxes, adding popup file dialogs, adding a Music controller as an autoloaded scene. It works fine as long as I drop the sound files in the game directory so Godot can import them. You just can’t call foreign sounds, or images, or models, or anything else for that matter.

Sylkie | 2019-11-27 07:29