A console-based music player implemented in C using circular doubly linked list data structure for playlist management and SDL2 for audio playback.
- Features
- Project Structure
- Dependencies
- Installation
- Building and Running
- Usage
- Implementation
- Data Structures
- API Reference
- Contributing
- License
- Circular Doubly Linked List: Custom data structure for playlist management
- Audio Playback: SDL2 and SDL2_mixer for playing .wav files
- Circular Navigation: Seamless next/previous song navigation
- Song Selection: Play songs by index number
- Interactive Menu: Console-based user interface
- Pause/Resume: Real-time playback control
- Current Song Indicator: Visual feedback in playlist display
- Memory Management: Proper resource allocation and cleanup
C-Music-Player/
├── src/
│ ├── main.c # Program entry point
│ ├── music_player.c # Core implementation
│ └── music_player.h # Header declarations
├── songs/ # Sample audio files
├── docs/
│ └── IMPLEMENTATION_GUIDE.txt
├── Makefile # Build configuration
└── README.md # Project documentation
- SDL2: Cross-platform multimedia library
- SDL2_mixer: Audio mixing library
- C Compiler (GCC, Clang, or MSVC)
- CMake (optional)
- Git
# Install vcpkg
git clone https://github.com/Microsoft/vcpkg.git
cd vcpkg
./bootstrap-vcpkg.bat
# Install dependencies
./vcpkg install sdl2:x64-windows
./vcpkg install sdl2-mixer:x64-windows
./vcpkg integrate install
sudo apt update
sudo apt install libsdl2-dev libsdl2-mixer-dev
brew install sdl2 sdl2_mixer
make # Build the project
make run # Build and run
make clean # Clean build files
cl.exe /I"path\to\sdl2\include" main.c music_player.c /link SDL2.lib SDL2_mixer.lib
gcc -std=c99 -Wall -o music_player main.c music_player.c `sdl2-config --cflags --libs` -lSDL2_mixer
./music_player # Linux/macOS
music_player.exe # Windows
Option | Function |
---|---|
1 | Show playlist |
2 | Play current song |
3 | Next song |
4 | Previous song |
5 | Select song by number |
6 | Pause/Resume |
7 | Stop |
8 | Exit |
========== MUSIC PLAYER MENU ==========
1. Show playlist
2. Play current song
3. Next song
4. Previous song
5. Select song by number
6. Pause/Resume
7. Stop
8. Exit
=======================================
Enter your choice: 1
========== PLAYLIST ==========
1. >> Song Title 1 << (Currently selected)
2. Song Title 2
3. Song Title 3
==============================
The project follows a three-file modular design:
File | Purpose | Lines |
---|---|---|
music_player.h |
Data structures and function declarations | 46 |
music_player.c |
Core implementation and algorithms | ~200 |
main.c |
Program entry point and user interface | 103 |
[Song1] ⇄ [Song2] ⇄ [Song3] ⇄ [Song4] ⇄ [Song5]
↑ ↓
←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←
- Each node contains song metadata
- Circular connections enable seamless navigation
- Bidirectional traversal support
typedef struct SongNode {
char song_name[100]; // Display name
char file_path[200]; // File path
int duration; // Duration in seconds
struct SongNode* next; // Next song pointer
struct SongNode* prev; // Previous song pointer
} SongNode;
typedef struct MusicPlayer {
SongNode* current_song; // Currently selected
SongNode* playlist_head; // Playlist start
Mix_Music* current_music; // SDL music object
int is_playing; // Playback state
int is_paused; // Pause state
int playlist_size; // Total songs
} MusicPlayer;
MusicPlayer* create_music_player()
SongNode* create_song_node(const char* name, const char* path)
void cleanup_player(MusicPlayer* player)
void add_song_to_playlist(MusicPlayer* player, const char* name, const char* path)
void display_playlist(MusicPlayer* player)
void play_song_by_index(MusicPlayer* player, int index)
void play_current_song(MusicPlayer* player)
void pause_resume_song(MusicPlayer* player)
void stop_song(MusicPlayer* player)
void next_song(MusicPlayer* player)
void previous_song(MusicPlayer* player)
int initialize_sdl()
void cleanup_sdl()
Operation | Time Complexity | Space Complexity |
---|---|---|
Add Song | O(1) | O(1) |
Navigation | O(1) | O(1) |
Search by Index | O(n) | O(1) |
Display Playlist | O(n) | O(1) |
- Fork the repository
- Create a feature branch (
git checkout -b feature/new-feature
) - Commit changes (
git commit -am 'Add new feature'
) - Push to branch (
git push origin feature/new-feature
) - Create Pull Request
- Follow C99 standard
- Use descriptive variable names
- Add comments for complex logic
- Maintain consistent indentation
This project is licensed under the MIT License - see the LICENSE file for details.
- SDL2 Development Team for the multimedia library
- Course instructors for project requirements
- Open source community for inspiration