So i am creating a class that have to be called by other class and when i try it with the ide of pycharm it is working but with the console i am having some problems. (if it works with the ide it should not be problem of the path)
The class MySoundPygame:
import pygame as pygame
import time
class MySoundPygame:
def __init__(self, son):
#print("constructor")
self.son = son
pygame.mixer.pre_init(frequency=44100, size=-16, channels=1, buffer=512)
pygame.mixer.init()
self.sound1 = pygame.mixer.Sound(son)
def setSong(self, s):
try:
print(s)
self.sound1 = pygame.mixer.Sound(s)
self.sound1.play()
time.sleep(self.sound1.get_length())
res = {
'code': 200,
'message': 'ok'
}
return res
except:
res = {
'code': 500,
'message': 'Error'
}
return res
The general class that includes play music and other things, i am calling it with:
from .sound.MySoundPygame import MySoundPygame
song = MySoundPygame('/home/pi/Desktop/python/proyecto/audio/intro.mp3')
def putSoundTrack(self, nameSong):
print("entra")
res = song.setSong(nameSong)
print(res)
return res
But i get this error in console:
File "/home/pi/Desktop/python/proyecto/sound/MySoundPygame.py", line 13, in __init__
self.sound1 = pygame.mixer.Sound(son)
pygame.error: Unable to open file '/home/pi/Desktop/python/proyecto/audio/intro.mp3'
Thanks for the help!