Skip to content

A console-based music player implemented in C using circular doubly linked list data structure for playlist management and SDL2 for audio playback.

License

Notifications You must be signed in to change notification settings

pvba-py/C-Music-Player

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

C Music Player with Circular Doubly Linked List

A console-based music player implemented in C using circular doubly linked list data structure for playlist management and SDL2 for audio playback.

Table of Contents

Features

Core Functionality

  • 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

Bonus Features

  • Pause/Resume: Real-time playback control
  • Current Song Indicator: Visual feedback in playlist display
  • Memory Management: Proper resource allocation and cleanup

Project Structure

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

Dependencies

Required Libraries

  • SDL2: Cross-platform multimedia library
  • SDL2_mixer: Audio mixing library

System Requirements

  • C Compiler (GCC, Clang, or MSVC)
  • CMake (optional)
  • Git

Installation

Windows (vcpkg)

# 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

Linux (Ubuntu/Debian)

sudo apt update
sudo apt install libsdl2-dev libsdl2-mixer-dev

macOS (Homebrew)

brew install sdl2 sdl2_mixer

Building and Running

Using Make

make              # Build the project
make run          # Build and run
make clean        # Clean build files

Manual Compilation

Windows (MSVC)

cl.exe /I"path\to\sdl2\include" main.c music_player.c /link SDL2.lib SDL2_mixer.lib

Linux/macOS (GCC)

gcc -std=c99 -Wall -o music_player main.c music_player.c `sdl2-config --cflags --libs` -lSDL2_mixer

Usage

Running the Program

./music_player    # Linux/macOS
music_player.exe  # Windows

Menu Options

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

Sample Interaction

========== 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
==============================

Implementation

Architecture

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

Circular Doubly Linked List

[Song1] ⇄ [Song2] ⇄ [Song3] ⇄ [Song4] ⇄ [Song5]
   ↑                                         ↓
   ←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←←
  • Each node contains song metadata
  • Circular connections enable seamless navigation
  • Bidirectional traversal support

Data Structures

SongNode

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;

MusicPlayer

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;

API Reference

Core Functions

Memory Management

  • MusicPlayer* create_music_player()
  • SongNode* create_song_node(const char* name, const char* path)
  • void cleanup_player(MusicPlayer* player)

Playlist Operations

  • 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)

Playback Control

  • 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)

System Functions

  • int initialize_sdl()
  • void cleanup_sdl()

Algorithm Complexity

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)

Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/new-feature)
  3. Commit changes (git commit -am 'Add new feature')
  4. Push to branch (git push origin feature/new-feature)
  5. Create Pull Request

Code Style

  • Follow C99 standard
  • Use descriptive variable names
  • Add comments for complex logic
  • Maintain consistent indentation

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

  • SDL2 Development Team for the multimedia library
  • Course instructors for project requirements
  • Open source community for inspiration

About

A console-based music player implemented in C using circular doubly linked list data structure for playlist management and SDL2 for audio playback.

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published