0

I have been building a game and I have been trying to add some background music for the menu. When I run the code though, all I get is a windows sound (Either notification or error sound, I don't know which) and then it just runs the rest of the program.

def background_menu():
 winsound.PlaySound("Menu Music.mp3", winsound.SND_ALIAS)

thread = Thread(target=background_menu)
thread.start()
menu_title()

background_menu() plays the music: Which is called 'Menu Music.mp3'. As you can see I have used a thread to run it in the background with from threading import Thread at the begginning of the code. Then the function menu_title() displays the rest of the menu. I am trying to use the thread to run it in the background. I think python just can't access the file (Which is in the same folder btw) I have also tried running as administrator and I am logged in as administrator. No syntax error appears.

SmartBaby
  • 11
  • 4
  • I think that winsound only supports WAV files when that function is called with the SND_FILENAME flag. – Dan D. May 06 '21 at 05:06
  • @PacketLoss Thanks but I don't appear to have pygame which I need for that. Any ideas? – SmartBaby May 06 '21 at 05:38
  • Install a module that can handle `mp3` . I'm unsure if Python natively supports MP3 playing. – PacketLoss May 06 '21 at 05:40
  • Many of python libraries like `sounddevice` don't play mp3 or m4a natively. They requires `pydub` to convert mp3 to wav which is time consuming and inconvenient. Not sure if it is because of license - it's always better to convert those into wav or flac sort of license-free codecs. – jupiterbjy May 06 '21 at 06:41
  • If you don't have `pygame`, install it. At an Administrator command prompt: `pip install pygame`. The module recommends Python 3.7.7 or later. – BoarGules May 06 '21 at 08:01

0 Answers0