How to play music using pygame (Python)
Question: I am trying to play an .mp3 file using pygame. Here is my code:

    
    
    import pygame
    
    pygame.init()
    pygame.mixer.init()
    
    pygame.mixer.music.load('MSM.mp3')
    pygame.mixer.music.play(0)
    
    pygame.event.wait()
    

This however does not actually play the file. The audio file is located within
the same folder as the .py file.


Answer: The pyGame docs suggest using the pygame.mixer.pre_init() method before the
top-level pygame.init() on some platforms.

> "Some platforms require the pygame.mixer module for loading and playing
> sounds module to be initialized after the display modules have initialized.
> The top level pygame.init() takes care of this automatically, but cannot
> pass any arguments to the mixer init. To solve this, mixer has a function
> pygame.mixer.pre_init() to set the proper defaults before the toplevel init
> is used." <https://www.pygame.org/docs/ref/mixer.html#pygame.mixer.init>

