A basic MP3 player in C using libmpg123 and libao libraries. This project allows you to play, pause, and stop MP3 files from your terminal.
- Play MP3 Files: Plays the specified MP3 file.
- Pause Playback: Toggle pause and play with the spacebar.
- Basic Error Handling: Handles basic errors during initialization and playback.
Ensure you have the following libraries installed:
libmpg123
libao
On Debian/Ubuntu systems, you can install these using:
sudo apt-get install libmpg123-dev libao-dev
clang main.c playmp3.c -o playmp3 -lmpg123 -lao
chmod +x install.sh
Run the script:
./install.sh
This will create an executable called mp3player in your current directory.
- Add your mp3 file to the project directory.
- In the main() function of main.c, replace "add you music here .mp3" with your mp3 file name.
- Compile the code.
- Run the executable:
./mp3player
init_PlayMP3(PlayMP3* mp3):
Initializes the MP3 player.setMusic(PlayMP3* mp3, char* track)
:: Sets the MP3 file to play.play(PlayMP3* mp3)
: Plays the MP3 file. Toggles pause/play with spacebar.cleanup_PlayMP3(PlayMP3* mp3)
: Cleans up after MP3 playback is done.stop(PlayMP3* mp3)
: Stops MP3 playback.isSpacePressed()
: Checks if the spacebar is pressed (non-blocking).
- Handle errors effectively in your application, especially where resources are initialized and used.
- Avoid memory and resource leaks by freeing unused resources.