import pygame
file = 'some.mp3'
pygame.init()
pygame.mixer.init()
pygame.mixer.music.load(file)
pygame.mixer.music.play()
This outputs, "Process finished with exit code 0", but it doesn't play anything. How can I resolve this problem?
import pygame
file = 'some.mp3'
pygame.init()
pygame.mixer.init()
pygame.mixer.music.load(file)
pygame.mixer.music.play()
This outputs, "Process finished with exit code 0", but it doesn't play anything. How can I resolve this problem?
It seems the audio does not play because of the way you have imported it. The code below plays the sound as expected. Nothing has changed here except that rather than
import pygame
it usesfrom pygame import mixer
. This may be due to the fact Pygame is a package but I'm not sure.Here is a super easy way.
try this one.
Try this,
you will need to install Tkinter, however it will hopefully work and you wont need to manually set the time. If this worked please let me know, I did test this on my computer but sometimes things just don't what to work. I will try to help you if I can.
The music stops because it's an asyncronous event, which means it'll keep going with the script. then, the script stops instantly, not giving the music a chance to start. as stated before, you could use
however, even better is
pygame.event.wait()
, as it'll wait for all asynchronous events to end.I've found a good solution from thepythongamebook.com: