Godot Version
4.6.1
Question
Hello, I am trying to figure out how to get the name of what song is playing in an AudioStreamRandomizer, and haven’t been able to find anything.
I’ve tried doing stream.resource_path.get_file().get_basename() but that just gave me “music”, which is the name of the folder where I stored all of the music files.
Does anyone know anything that might be able to help me here?
Use this:
stream.resource_path.get_file().to_snake_case().trim_suffix(".mp3").trim_suffix(".ogg").trim_suffix(".wav").capitalize()
If your sound file is an OggVorbis or a correctly formatted WAV file and has Title metadata, this will also work:
stream.get_tags()["title"]
You can see all song metadata by doing:
print(stream.get_tags())
1 Like
After looking into this more, I don’t think doing this is possible, as it always just returns the folder the songs are in instead of the songs themself. If anyone else is looking to do this, I suggest making a script to randomly choose an audio file instead of using an AudioStreamRandomizer.
Not only is it possible, I have a plugin that does it for you.
Check out my Sound Plugin. It literally puts the information in the Output window, as well as sending out a signal with the info that anything can listen to and use for display.
This is from a game I’m working on that uses the plugin.
(
It’s right under PAUSED.)
Or from the plugin test in the plugin itself:
It even has an example pf colored scrolling marquee for the currently playing song:
I just didn’t offer that as a solution because you seemed to want to do it yourself.
Did neither of the answers I gave you work for you?