-1

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!

4
  • Python is not a compiled language Commented Aug 28, 2021 at 13:11
  • Make sure the song2.mp3 file is there Commented Aug 28, 2021 at 13:12
  • Try to include the absolute path to the song file Commented Aug 28, 2021 at 13:13
  • Your songsData list is empty before it is called? Commented Aug 28, 2021 at 13:26

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

4 Comments

no need to fight guys! Same issue with vlc.. if Im writing the name of the file it works but if im getting the name from function it doesn't work
@omerap12 Make sure the file is actually there or that there aren't any typos in your file names.
I checked, file there and no typos

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.