Game programming is very rewarding nowadays and it can also be used in advertising and as a teaching tool too. Game development includes mathematics, logic, physics, AI and much more and it can be amazingly fun. In python, game programming is done in
pygame and it is one of the best modules for doing so.
Note: For more information, refer to Introduction to pygame
In order to play music/audio files in
pygame.mixer is used (pygame module for loading and playing sounds). This module contains classes for loading Sound objects and controlling playback. There are basically four steps in order to do so:
- Starting the mixer
- Loading the song.
- Setting the volume.
- Start playing the song.
Below is the implementation.
This code will also play the “song.mp3” file.
- Tic Tac Toe GUI In Python using PyGame
- Python - Moving an object in PyGame
- Python | Display images with PyGame
- Python | Display text to PyGame window
- Python | Drawing different shapes on PyGame window
- Python | Making an object jump in PyGame
- Python - Drawing design using arrow keys in PyGame
- Python program to reverse the content of a file and store it in another file
- reStructuredText | .rst file to HTML file using Python for Documentations
- Create a GUI to convert CSV file into excel file using Python
- Video to Audio convert using Python
- Python - Add audio files in kivy
- YouTube Media/Audio Download using Python | pafy
- Python | Speech recognition on large audio files
- Python - Get file id of windows file
- Introduction to pygame
- 8-bit game using pygame
- How to initialize all the imported modules in PyGame?
- How to create Buttons in a game using PyGame?
- How to add color breezing effect using pygame?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.