0 votes

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.

asked Nov 26, 2019 in Engine by Sylkie (34 points)

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!

2 Answers

0 votes

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?

answered Nov 26, 2019 by Sylkie (34 points)

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

0 votes

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

func _ready():
    add_child(_player)
answered Nov 27, 2019 by Dlean Jeans (3,873 points)

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.

enter image description here

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.