The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

0 votes

I wonder if there is any way to play a sound or get them into item list like a music player from file browser. I want to have a folder or player could make one and scan that folder in game to take a list of the music types in game, also play them. Is that possible to do?

Godot version 3.4.3
in Engine by (29 points)

1 Answer

0 votes
Best answer

This isn't everything you've asked for, but here's how to open and play an audio file (mp3, wav, ogg) within your game:

In a new scene add an AudioStreamPlayer and FileDialog node as children of the root node. Since we only want to open files set the FileDialog's mode to "Open File" in the inspector. FileDialog nodes can't be visible by default, so you'll also want a Button that will make it visible whenever you press it.

Once you have a script attached to the root node you can connect the Button's pressed() signal and the FileDialog's file_selected() signal to the script. The following code should get everything to work:

func _on_Button_pressed():
    $FileDialog.visible = true

func _on_FileDialog_file_selected(path):
    var song : AudioStream = load(path)

As an FYI the volume might be really loud by default, so turn it down using AudioStreamPlayer's Volume Db property in the inspector.

by (88 points)
selected by

This just doesn't work,

I have your code exactly, upon trying to load i get the error
" _load: No loader found for resource: C:/Users//audio.mp3."

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 Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.