S
S
SuperZombie2020-09-16 21:09:38
Python
SuperZombie, 2020-09-16 21:09:38

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()

Playsound library:
from playsound import *
def grass():
    playsound('Data\\Music\\grass.mp3')


Upd: I compiled the exe along with the console and gave the following error:
5f625e36b041c741466998.jpeg

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
SuperZombi, 2020-09-16
@SuperZombie

Solution: I converted the mp3 file to wav and the exe works fine for me.

S
StarCatSTT, 2020-09-16
@StarCatSTT

Add the win32com module to the assembly.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question