Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pygame load
#1
Hello
I'm relatively new to Python. Whilst writing an mp3 player I encounter an error.

I have in a previous step created a simple textfile with paths to mp3 files. After reading the file I use a for loop
pygame.mixer.init()
for i, line in enumerate(f):
    if i == 0:
        print(line)
        path, filename = os.path.split(line)
So far nothing strange
For testing purposes I also write variable line (full path to mp3 file) as well as variable path and filename after the split.
And change the working directory
        print('Path: ' + path)
        print('Filename: ' + filename)
        os.chdir(path)
No to call the player (pygame) I use filename in the load() function and then play
        pygame.mixer.music.load(filename)
        pygame.mixer.music.play()
Getting the error pygame.error: "Couldn't open '01-som_vatten.mp3"
If I instead directly write
pygame.mixer.music.load('01-som_vatten.mp3')
It works fine.

Output of the prints are:
Path: C:\temp\ett\tva
Filename: 01-som_vatten.mp3

I cannot work out what is the difference between writing the mp3 filename directly and using a variable. Could it be the wrong variable typ?

Regards
Johan
Reply


Messages In This Thread
Pygame load - by Kangen - Aug-07-2019, 07:50 AM
RE: Pygame load - by metulburr - Aug-07-2019, 12:21 PM
RE: Pygame load - by Kangen - Aug-08-2019, 09:53 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Pycharm dosnt load pygame Matres 1 2,004 Mar-16-2020, 02:15 AM
Last Post: Larz60+
  [pyGame] Load Image, Problem Found ! JamieVanCadsand 2 8,808 Sep-29-2017, 06:26 PM
Last Post: metulburr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020