Python Forum
How to embed mp3 file with Pyinstaller
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to embed mp3 file with Pyinstaller
#1
I 'm tryin to use an mp3 in my app.
This is how:
def _response_to_alert(self):
  if getattr(sys, 'frozen', False):
    # we are running in a bundle
    bundle_dir = sys._MEIPASS
else:
    # we are running in a normal Python environment
    bundle_dir = os.path.dirname(os.path.abspath(file))
file = os.path.join(bundle_dir, 'foghorn.mp3')

pygame.mixer.music.load(file)
pygame.mixer.music.play(-1)
In my spec file, I have: datas= [('betws.ui','.'), ('foghorn.mp3', '.')],

But it' s not working.
What am I doing wrong?
Reply
#2
Finally the code works, I just had put it the wrong place!
Reply
#3
(May-25-2017, 08:37 PM)panoss Wrote: Finally the code works, I just had put it the wrong place!

Please teach me how to do this,
I been finding so many source online but still have no idea how to do this..
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  why: pyinstaller generates a different exe file every time momo1313 1 74 Jan-23-2026, 03:17 PM
Last Post: DeaD_EyE
  Errors during run .exe file generated with Pyinstaller BushyAxis793 4 5,610 Mar-25-2025, 05:57 PM
Last Post: BushyAxis793
  Executable file compiled by PyInstaller does not work on Windows 7 amusaber 1 4,584 Jul-11-2024, 02:59 PM
Last Post: DeaD_EyE
  Embed Matplotlib Graph to Tkinter? dimidgen 0 3,083 Mar-04-2024, 07:40 PM
Last Post: dimidgen
  Using pyinstaller with .ui GUI files - No such file or directory error diver999 3 11,603 Jun-27-2023, 01:17 PM
Last Post: diver999
  Interactive plots that can be embed in web page mouse9095 1 1,680 Jun-12-2023, 04:51 PM
Last Post: deanhystad
  embed python script in C programm gucio321 0 1,439 Feb-11-2023, 10:47 AM
Last Post: gucio321
  best way to embed passwords into scripts mikey6785 3 6,322 Aug-31-2022, 08:22 AM
Last Post: DeaD_EyE
  Pyinstaller distribution file seems too large hammer 4 6,415 Mar-31-2022, 02:33 PM
Last Post: snippsat
  problem with pyinstaller to create an executable file atlass218 0 4,042 May-15-2021, 11:01 AM
Last Post: atlass218

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020