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
  Embed Matplotlib Graph to Tkinter? dimidgen 0 182 Mar-04-2024, 07:40 PM
Last Post: dimidgen
  Using pyinstaller with .ui GUI files - No such file or directory error diver999 3 3,076 Jun-27-2023, 01:17 PM
Last Post: diver999
  Interactive plots that can be embed in web page mouse9095 1 571 Jun-12-2023, 04:51 PM
Last Post: deanhystad
  embed python script in C programm gucio321 0 580 Feb-11-2023, 10:47 AM
Last Post: gucio321
  best way to embed passwords into scripts mikey6785 3 2,181 Aug-31-2022, 08:22 AM
Last Post: DeaD_EyE
  Pyinstaller distribution file seems too large hammer 4 2,632 Mar-31-2022, 02:33 PM
Last Post: snippsat
  problem with pyinstaller to create an executable file atlass218 0 2,536 May-15-2021, 11:01 AM
Last Post: atlass218
  Embed Python blender code flaviu2 0 1,453 Nov-16-2020, 06:33 PM
Last Post: flaviu2
  Pyinstaller create this error :“File ”multiprocessing\connection.py“, line 691 Formationgrowthhacking 2 3,573 Apr-30-2020, 10:26 AM
Last Post: buran
  the exe file by generated by pyinstaller ,can't get the PYTHONPATH roger2020 11 6,857 Jan-14-2020, 11:07 AM
Last Post: roger2020

Forum Jump:

User Panel Messages

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