pythonbackground-musicpgzero

Is there a way to play background music in python pgzero?


I currently have an audio file in the correct directory but I can't seem to find a command that will play and loop the song. Is it the same as just playing the sound? If not, what is the syntax to play the music?


Solution

  • Pygame Zero seems to make this easy. The methods for playing longer music tracks are different than those for playing short sound clips.

    If you want to play a music file called tune1 place it inside a directory below your code file called "music" with the file name tune1.mp3 or tune1.ogg.

    Inside your program running the following will play the music on an infinite loop

    music.play('tune1')
    

    References: