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.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
- MoviePy – Playing video clip file for n times
- MoviePy – Checking if Video File Clip is playing at given time
- Python VLC MediaPlayer - Checking if it is playing or not
- Python VLC MediaPlayer - Start Playing it
- Playing Youtube Video using Python
- Python VLC MediaListPlayer - Currently Playing
- Python VLC MediaListPlayer - Playing Item at given index
- Python VLC MediaListPlayer - Playing Item
- Python VLC MediaListPlayer - Playing Next Item
- Python VLC MediaListPlayer - Playing Previous Media
- Convert PDF File Text to Audio Speech using Python
- Access metadata of various audio and video file formats using Python - tinytag library
- Python | Display images with PyGame
- Python | Drawing different shapes on PyGame window
- Python | Making an object jump in PyGame
- Python - Moving an object in PyGame
- Python - Drawing design using arrow keys in PyGame
- Tic Tac Toe GUI In Python using PyGame
- Binary Search Visualization using Pygame in Python
- Snowfall display using Pygame in Python
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.