0

I have an array of Song class objects that I created and I'm having problem playing music with pygame mixer.

photo

as you can see, I have 4 songs in the working directory, I created an array of Songs object which have information about the different song. on particular function that I have created is getIndexName() which returns the name of the file. the name of the array is songsData.

If I would call the function: mixer.music.load("song1.mp3) and then mixer.music.play() it works fine, however if I would call: mixer.music.load(songsData[1].getIndexName()) and then mixer.music.play()

I'm getting an error:

mixer.music.load(songsData[1].getIndexName())
pygame.error: Couldn't open 'song2.mp3

I think that I have to determine which file I want to play at compilation time, but I don't know If I think right. If I'm right is there any module that can play mp3 files (or wav) and I can determine which file at run-time? (like calling random).

thanks for youre help!

Rabbid76
  • 202,892
  • 27
  • 131
  • 174

1 Answers1

0

You can use the VLC module:

import vlc
p = vlc.MediaPlayer("file:///home/user/Music/song1.mp3")
p.play()

Or try https://stackoverflow.com/a/68964908/11844784

Petr L.
  • 414
  • 5
  • 13