1

I have a script, that when running it in vsc, plays sounds in mp3 with the library playsound, but when passing it to exe with autopytoexe, I added the foldier with all the music to the exe, but the music for some reason doesn't sound.

What occurs is, that when it reaches the part to play a sound, the ui, stops.

How could I fix this?

    import playsound
from playsound import playsound
perlita= random.random()
print(perlita)
if perlita >= 0.1000:

    NOMBRE_ARCHIVO = "sonidosos/1 day time frame.mp3"
    playsound(NOMBRE_ARCHIVO)
else:
    pass
Habi
  • 45
  • 6

1 Answers1

0

is this your complete code? Apart from the missing import of random, it works fine for me. I compiled it to exe using PyInstaller this might make a difference. You can try your self by installing PyInstaller with pip install pyinstaller and then run it with this command pyinstaller --onefile --noconsole --name="example" example.py. There are a multitude of options like --icon=path/to/icon.png, --onedir, ``--windowed` or others. Here is the complete documentation: https://pyinstaller.org/en/stable/usage.html

I hope this helps!

Olivier Neve
  • 299
  • 10
  • hi ... did the music play? – Habi Feb 21 '23 at 08:43
  • Yeah no problem for me. What i'd advise is to compile it with the only param being `--onefile` and once it's done, you will find it in `project_root/dist` (when I say `project_root` I mean your programs working directory). Move the executable to the root of your project so it can access the sound file in the same way running your code through the interpreter would have and run the executable through CMD, to avoid it closing the console as soon as it errors/finishes – Olivier Neve Feb 21 '23 at 08:57
  • Thaks! @Olivier Neve , it work ... but here is my problem, I need to wrapup the folder with the sounds .... is there any way I can do this? (iow: it doesnt work when making exe the foldier of sounds) – Habi Feb 21 '23 at 20:25
  • What I do when I have files to bind to my program is make a wizard with inno setup or an other installer compiler. This will allow you to link as many files as you want to your executable so when you run the installer it will create a folder with your program and all its dependencies. – Olivier Neve Feb 22 '23 at 08:45