How to Access Into Sound Files In Game

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

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?

:bust_in_silhouette: Reply From: EliTheBeeli

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.

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."

Sopuyy | 2022-12-07 21:14