Audio Playlist with Song Name

Been playing around with Unreal Engine after some time away, and a lot of stuff has changed. I was looking at going after the following:

  • Player loads the main menu to the game, which would display all menu options [done]
  • Music playlist would start playing a random song (currently, I have this setup in a cue just picking a random song)
  • Would display a widget in the bottom right showing the name of the song.

Issues I’m having: It appears that the music is random based on each time you re-open the game, and it just keeps looping that one song. How would I go about getting a TRUE random. (Once a song is finished it cycles through the list again)

Next: To my understanding of how others have tried to achieve getting the song name, the simple way would just be to insert these as strings, attached to each file somehow, and it would fetch the song name string associated to that song. The question is, how?

I’ve thought about going at this with level blueprints, or just putting a sound cue in the position of where the player start is on the map. But for the music to display the actual title that I attach to the string, what would be the best way? I’ve thought about arrays, etc. But don’t really have a solid direction to go in to where I can actually assign a string property to each song in the randomized list of the sound cue. Then I could just use get/set on that string as a variable.

Any help would be appreciated.

Just make a BP array with USoundBase as the type. Then add the sound waves directly (don’t use a sound cue) either as a public variable (so you can reuse your BP script) or do it as a default array. Make a copy of this array when the script starts (OnBeginPlay) so you can reset back to the original list.

Then when you play a song, randomly pick from this list (random int range between 0 and the size of the list). Remove the chosen item from the copied list so you don’t pick it again.Then play the audio with an audio component (spawn sound or add component to your BP actor). Then register a delegate function to be notified in BP when the song finishes.

Then when the song finishes do the above again until you don’t have any more songs in your copied list. Then when your list is empty re-copy to it from your original list and start over.

1 Like

I’m working on something similiar, how would I go about displaying the song name on the screen?

Many thanks,

P