# Using MPD with Cantata.

One of the common ways in which Linux users have been playing music on their computers has been a traditional way, which would be, with an application that has a GUI, and which runs in their user-space, and which therefore has access to a personal music folder. ‘Clementine’ and ‘Amarok’ are only two out of several applications which do this under Linux. But there is another way to stream music through a Linux computer, in the form of the “Music Player Daemon” (‘MPD’), that can be configured to run in the root file system, as a system process, and in the background, while using up far less RAM or CPU cycles than either of the top-heavy, GUI-driven apps use. And one good place to use such an arrangement is, if we want to have ‘relaxation music’ playing through our life space, but again, without taking up much in the way of resources on whichever computer is generating the sound output.

‘MPD’ itself has no user interface and is configured in a single configuration file, in the case when it is not configured per-user. Therefore, one thing that users and admins alike might do – but mainly plain users – is to install one out of numerous MPD Client programs, and the client program which I chose happens to have a GUI:

This front-end is named ‘Cantata’.

There already exist good references on the Web, on How to configure an ‘MPD’ system process, just using a Text Editor, and the command-line. (Yes, the stock client is installed with a package named ‘mpc’, and is driven from the command-line.) I think that the article which I just linked to is well-written, and that its author seems very knowledgeable.

The only problem with the article linked to above is, that the author just forgot to explain one fact. Not knowing this fact, and being new to how ‘MPD’ works, cost me several hours close to midnight on one recent day. I found this fact written in exactly one other article on the Web. Just so that other users do not suffer from the distress that can be caused, because they, too may want to run ‘MPD’, but caused, from not knowing this fact, I just decided to create the second spot on the Web that I know of, which mentions it…

(This fact concerns a possible problem in using ‘MPD’, due to which a single user’s private Music Collection does not want to appear.)

(Updated 11/26/2019, 13h05 … )

(As of 11/24/2019 : )

After I had set up ‘MPD’ as explained in the linked article, I felt I could next take the shortcut of doing further configuring, using the graphical front-end of my choice. Therefore, just before paying for a subscription to a music streaming service, I needed to test ‘MPD’ to see whether it was in fact working. And I felt that the best way to do that was, to have it play some of the music in my personal collection, from my hard drive.

Here is the problem I ran in to: Any instance of ‘MPD’ is only able to have a single Music Folder configured. Therefore, when using Cantata, the following settings dialog can deceive people who do not know this:

What this dialogue seems to suggest is, that multiple “Collections” can be set up simultaneously, and the dialogue even allows the user to choose a different Music Folder for each one. The problem with reading the GUI that way is, that this combination of settings only makes sense, if Cantata is being used as a remote-control for more than one ‘MPD’ instance, or, if ‘MPD’ is set up to run on a per-user basis, in which case Cantata can launch as many instances as it needs to, and tell each instance what to do.

Therefore, when the author linked to above gave the following command:

MPD_HOST=Password1@/run/mpd/socket mpc update

He was in fact telling ‘MPD’ to scan the folder:

/var/lib/mpd/music


NOT, his personal Music folder.

If ‘MPD’ is to have access to a user’s personal music folder, even though it has been set up to run as a system process, then that user must add himself or herself to the Groups which the User ‘mpd’ belongs to, restart ‘mpd’, and make sure that all the parent directories of his or her music collection are chmodded to ‘g+rx’.

I had already done that. But then, what I also needed to do was, to add a symlink to ‘/var/lib/mpd/music‘, that points to my home folder’s music sub-folder. Otherwise, my music folders did not exist, as far as the (correctly configured) ‘MPD’ instance was concerned.

So, the final result was that through ‘Cantata’ (after that one step that required root privileges to carry out), ‘MPD’ was also able to play my personal music, on my machine, and that because of this, I paid for a subscription to a streaming music service, from which it also plays.

I should also add the observation that a big problem in using ‘MPD’ from any of its user interfaces / clients is, that when told to manipulate playlists normally, that consist entirely of URLs, the setup tends to garble the URL and in some cases, truncate them. Depending on how many special characters or sub-domains the URLs contain, this can happen every time we try to encue, or, create a playlist.

My solution to that problem was, to use a text editor to add the URLs to the playlists (.M3U-Files), in the ‘MPD’ instance’s playlists folder.

Caveat:

Adding a URL to such an .M3U-File causes ‘MPD’ to update its database – simply leading to a new entry in the playlist. However, deleting one of the URLs already indexed, results in some small amount of corruption to the database, which can only be repaired by Removing the entire playlist (from within ‘Cantata’). For that reason, I needed to re-create the playlist in question more than once, and now keep a backup copy of the .M3U-File in another directory.

(Update 11/26/2019, 0h05 : )

One thing which I have been able to do was, to make the Folder View of the Sidebar, of ‘Cantata’, reveal files and folders more than 3 levels deep in total:

The way I achieved this was, to examine every symlink that existed within my music hierarchy – under my Home Directory – to make sure that really, all the music files had the correct permission-bits set.

(Update 11/26/2019, 13h05 : )

In other words, If ‘MPD’ runs across a sub-directory of the Music Directory, that it has permission to read and traverse, but if it doesn’t have permission to read any of the files within, then what ‘MPD’ will do is to omit the entire directory from its database, for the convenience of the user.

Dirk