mardi 15 décembre 2020

Random audio lecture in python not working : pygame.error: Couldn't open '48.mp3'

Am a completely new on python, here is my problem am having,

I have a raspberry pi4b and I was making a script that will play an audio randomly. But the thing is i have tried everything that i can but its still not working and everytime am having this error message : pygame.error: Couldn't open '48.mp3'

Here is the script (in python):

import random
import pygame
from pygame.locals import *

pygame.init()

#in the folder where the audio files are, there are 150 audio files

playlist = ['001.mp3', '002.mp3','003.mp3','012.mp3','017.mp3','014.mp3','048.mp3']
pygame.mixer.init()
 
pygame.mixer.music.load(random.choice(playlist))
pygame.mixer.music.play()
pygame.quit() 

And this is the message am getting everytime (the random function seem to work but can't open the file)

pygame 1.9.4.post1
Hello from the pygame community. https://www.pygame.org/contribute.html
Traceback (most recent call last):
  File "/home/pi/Desktop/audio/TestAvecVlc.py", line 8, in <module>
    pygame.mixer.music.load(random.choice(playlist))
pygame.error: Couldn't open '48.mp3'
>>> 

Another one (we can see that this time its the file 012.mp3) :

pygame 1.9.4.post1
Hello from the pygame community. https://www.pygame.org/contribute.html
Traceback (most recent call last):
  File "/home/pi/Desktop/audio/TestAvecVlc.py", line 8, in <module>
    pygame.mixer.music.load(random.choice(playlist))
pygame.error: Couldn't open '012.mp3'
>>> 

I have also tried to rename the audio files and here again thats what am having :

pygame 1.9.4.post1
Hello from the pygame community. https://www.pygame.org/contribute.html
Traceback (most recent call last):
  File "/home/pi/Desktop/audio/TestAvecVlc.py", line 8, in <module>
    pygame.mixer.music.load(random.choice(playlist))
pygame.error: Couldn't open 'fa.mp3'
>>> 

As we can see here the random audio is correctly selected but still the same message :

pygame 1.9.4.post1
Hello from the pygame community. https://www.pygame.org/contribute.html
Traceback (most recent call last):
  File "/home/pi/Desktop/audio/TestAvecVlc.py", line 8, in <module>
    pygame.mixer.music.load(random.choice(playlist))
pygame.error: Couldn't open 'ba.mp3'
>>> 

I don't knwo what to do .... Can someone help about this issue please ? Thanks for your help :)




Aucun commentaire:

Enregistrer un commentaire