title: Pygame audio not playing on startup (Raspberry pi)
body: <p>I seem to be having difficulty with executing a pygame program on boot up. I have a raspberry pi 3 model B running the latest versions of the required libraries. I am simply trying to play a wav file through pygame when a button is pressed. I substituted an “led.on” script for the pygame to ensure my program was being started on boot-up and it ran flawlessly. However, when I try to use pygame on boot up it will not play the audio file. Although pygame will play the file in the terminal, it will not play on startup.
  I am using crontab to run the program from boot. Using the following line:</p>
  <p><code>@reboot python /home/pi/test.wav &amp;</code></p>
  <p>And the python code:</p>
  <pre><code>from gpiozero import Button
  
  import pygame.mixer
  
  pygame.mixer.init()
  
  song=pygame.mixer.music.load(‘/home/pi/test.wav’)
  
  btn=Button(27)
  
  while True:
      btn.when_pressed=(pygame.mixer.music.play)
  </code></pre>
  <p>Any help would be greatly appreciated, thank you!</p>