Sunday, January 17, 2021

Media player daemon: Playing music with mpd and mpc

My love for the Media player daemon is clear if you have gone through my other blog posts. I like its concept. It is simple, straightforward and does what it is supposed to do. Play music. The combination of mpd and mpc is awesome. It is akin to watching a good buddy movie. They are just so perfect together. If you are a person who would like to "see" the song list and control the music by visual controls, you are also covered. There are a plethora of clients for the mpd. In terms of simplicity an curtness, there is nothing closer to mpc. 

 This post is about the barest minimum required to start playing music without the screen filling up with the file names. Installing mpd on arch is as simple as a, b, c.... really. 

pacman -S mpc mpd 

copy /etc/mpd.conf to .config/mpd/mpd.conf Overwrite the file with the information below 

--------------------------------

# Recommended location for database 

db_file "~/.config/mpd/database" 

# Logs to systemd journal 

log_file "syslog" 

# The music directory is by default the XDG directory, uncomment to amend and choose a different directory 

# I like to symlink all my sources of music to the default Music folder. Ultimately, tell the directory where # your media is stored. 

music_directory "~/Music/music" 

# Uncomment to refresh the database whenever files in the music_directory are changed 

#auto_update "yes" 

#These are my choices for the requisite files. Al these files are required. So, if you would like to change the locations, do so. But ensure that these directories are user accessible with write permissions. 

playlist_directory "~/.config/mpd/playlists" 

pid_file "~/.config/mpd/pid" 

state_file "~/.config/mpd/state" 

sticker_file "~/.config/mpd/sticker.sql" 

#This is if you are using pulse audio. If you are using also, change accordingly audio_output { 

type "pulse" 

name "pulse audio" 

----------------------------

Save the file. reboot 

Now, the first step ensure that mpd is running.

mpd 

On success, the above command will not spit out anything. Now, the daemon is running and waiting to server you music. Let us now, build a database of songs available in our directory we specified in mpd.conf. 

Now we have to populate our database. Before doing this step, I suggest you to check whether your music has good metadata related to track names, albums, etc. If not, it is always good to invest some time in editing the id3 tags of your music. This will help us in getting "that" song to play. 

Once you are sure of your metadata. Go ahead and build the database. 

mpc update 

The above command will take some time. Give it a few minutes. To know whether all the songs have been added to the database run the command below. If you see that the last song is the same when you run the command below, multiple times, then you know that the database is completely built. 

mpc listall 

Of course, your database is going to be huge. And depending on your mood, you would like to pick and choose. Let us now create a playlist based on certain criteria. You are now in that retro dance mood and would like to listen to the evergreen Jackson. There are multiple ways to search for Jackson songs in your database based on how your id3 tags are created. If you would like to add all albums with the name Jackson in your album name then you would do 

mpc searchadd album jackson 

I know, Now you want to see what is the playlist which is create by the above command, For this you would 

mpc playlist 

Now, you remembered that there are certain files with Jackson in their names but are not part of an album with jackson in them. Then to add all the songs with title containing jackson 

mpc searchadd title jackson 

Now, check your playlist again 

mpc playlist 

The nerd in you is glowing. You now have all the titles you want to play in your playlist. Hit it. 

mpc play 

Of course, you have got used to seeking music with other command line players by hitting the arrow keys. However, the command for seeking in mpc is(Again, you can map keys and what not.....) 

mpc seek +00:04:00 

The above command is for seeking the song by 04 minutes. I think the logic is clear. This works both for individual files or if you have a file with multiple songs. If you have individual songs in files then 

mpc seek +80% 

would be better. 

 In the middle of your listening pleasure, you would like to know the details of the song being played now

 mpc status  

will give you information regarding the present song and plenty other data related to the present playlist.

For seeking back change the + sign to -. An alias for all the above would be best. 

The post is not complete without gratitude to all the devs and users who make all this possible. The GNU/Linux land and the BSD universe have not stopped surprising me.

 

 PS: Just, one more thing.

 mpc searchplay title jackson

 which will create the playlist and start playing.

No comments:

Post a Comment

Nobody can deter me away from "free as in freedom" concept seeded by Sri RMS. See to it that u dont make fun of my belief. If u think otherwise, no need to comment.