Answer the question
In order to leave comments, you need to log in
Why is there no sound after compiling Pygame via Pyinstaller?
Good day to all! I am writing a game in Python using tkinter.
Added background music and sounds.
The music in the background is played by Pygame (Thread plays in a separate thread), and the sounds are played by Playsound.
When working with the py file itself, there are no problems.
Compiling to exe using Pyinstaller. First the pywin32 error came out. Installed. Now there is no error, but there is still no music in the game. The second library that plays sounds works correctly.
The problem is either in Pygame or Thread.
At the same time, Thread is also used to count seconds and they are correctly counted.
Who can help with this?
Pygame library:
from pygame import mixer
stop = False
volume = 1
def play(stop, volume):
mixer.init()
mixer.music.set_volume(volume)
mixer.music.load('Data\\Music\\music.mp3')
mixer.music.play(-1)
while mixer.music.get_busy():
if stop == True:
mixer.music.pause()
break
# Вызов выполнения функции в фоне
x = threading.Thread(target=play, args=(stop, volume), daemon=True)
x.start()
from playsound import *
def grass():
playsound('Data\\Music\\grass.mp3')
Answer the question
In order to leave comments, you need to log in
Solution: I converted the mp3 file to wav and the exe works fine for me.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question