Table of contents:

What is MPD:

Music player Daemon known as MPD takes care of managing your media files and organize them according to their MetaData it uses an in-memory database to deal with your taste of music and it has streaming-ready facilities to use it remotely, you can combine MPD with other tools like Beets and IceCast and make a delicious and tasty combination!

Why should I use it?

I have a PC(1) and a Laptop(2) in my house and also another laptop(3) in my workplace and finally I own a cellphone(4) and a tablet(5), according to my needs I switch between them to do my stuff, meanwhile I search for music genres which fits best to my mood at that specific time to boost my performance, after that guess what, I download mp3 files accordingly.

The problem I have Is that mostly I tend to listen to those songs that I experienced good feelings therefore Imagine the scenario that I’m reading a book while listening music in my tablet and geeing the best amount of information and joy at the same time.

After a while I’ll probably want to use the music again and yes the problem begins here, I will transfer my files to my current device which is not always a particular one and use it there, the problem happens again and Ill waste at most 5 time of the music size as I have 5 different devices and more importantly tons of motivation and energy while performing these routine and boring steps, In my opinion I need a solid space which solves the main issue and even adds more interesting thing to it.

Currently I’m working on a Music related project so I need to use the tool, that’s another reason for me to understand the tool , in this place you can find what I grasp during learning process.

Installation

For most linux Distros you can install it from your package manager.

in Ubuntu just hit the command sudo apt install mpd

Lunching systemd daemon

If you are using systemd you can either start MPD’s daemon as system unit or user unit, the difference is from which file you are going to customize the service, if you are running it as a user unit the file would be in ~/.config/mpd/mpd.con.f and if you are using it as a system unit it’s going to be in /etc/mpd.conf

Configuration

Let’s make it abstract a little bit, There are there important component I want to customize through directives in configuration file:

  • Input
  • Middleware
  • Output

In my case I want my Input read my mp3 files and predefined playlist files from two different sources, lets say from /home/kave/Music/mp3 and /home/kave/Music/playlists. for Output I will use Icecast to be able to hear yo songs remotely and for sake of simplicity I don’t want any middleware.

Input

Path to MP3 file

To tell MPD to scan an specific directory we can use music_direcroy directive, in my case I want MPD to scan /home/kave/Music/MP3 so I’ll put music_direcroy "/home/kave/Music/MP3" in the Configuration file.

Path to Playlist files

Similarly to load playlist files, just use playlist_directory directive and done, in my case it’s playlist_directory "/home/kave/Music/playlist".

Output

There is a popular misconception about MPD’s client/server architecture, if you are using an MPD instance somewhere else and you are trying to use a client software and you can’t hear the music you should know that there is nothing wrong with the service, the issue is the clients that are going to use MPD are just controllers, just like your controller for TV and you should not expect the client make any sound, Icecast is the software that allows you hear sound remotely.

IceCast

Icecast is a streaming media server, we are going to glue mpd and icecast together to be able to listen to sounds remotely, after installing icecast and setting it up you should add following block in your MPD’s configuration file, in my case it is: /etc/mpd.conf

audio_output {
	type   "shout"
	name   "My Shout Stream"
	host   "localhost"
	port   "8000"
	mount   "/mpd.ogg"
	password   "hackme"
	format   "44100:16:1"
}

Summarize

Now My file at /etc/mpd.conf looks like this:

music_directory   "/home/kave/Music"
playlist_directory   "/var/lib/mpd/playlists"

db_file	   "/var/lib/mpd/tag_cache"
log_file    "syslog"
pid_file    "/run/mpd/pid"
state_file   "/var/lib/mpd/state"
sticker_file   "/var/lib/mpd/sticker.sql"
bind_to_address   "localhost"

audio_output {
	type   "shout"
	name   "My Shout Stream"
	host   "localhost"
	port   "8000"
	mount   "/mpd.ogg"
	password   "hackme"
	format   "44100:16:1"
}

This is a simple example, as you see there are some other directives we have not explain yet, let’s make a table and explore their functionality.

name details
db_file The Music data base.
log_file If set it to syslog it logs to systemd’s journal, If set to a file path logs will store in the file.
pid_file The file where MPD stores its process ID.
state_file MPD’s current state is noted here. (doc)
sticker_file Path to sticker DB, “Stickers” are pieces of information attached to songs.(doc)
bind_to_address The network address to bind, clients can access it to control the service.

That’s my first confrontation with the tool.