# 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

## 6 thoughts on “Using MPD with Cantata.”

1. Riccardo Wanke says:

Hi,
I am getting troubles to set the access of Cantata to my music folder. I use an external USB drive (called “USBRDW”) I set to open automatically with full access and permission:

drwxrwxrwx+ 8 root root 4096 mai 3 11:55 USBRDW

I configured the first start of Cantata, with the “path/to/my/music/folder” and succeeded to connect it, but I don’t see it in Cantata’s Library, but if I browse the “Folders” I can access to the music.

I don’t see where is the problem.

[I tried also to run cantata from terminal as “superuser” (sudo) but it is the same]

if you have any advice, it would be great!

thanks
Riccardo

1. Dirk Mittler says:

Offhand, I’d say it’s hard for me to guess. I have a hint for you, though. In order for MPD to be able to access the individual files and folders – in your case, of the USB drive – not only do the parent folders’ permissions need to allow it (all the way up to the file system root), but all the sub-folders’ permissions need to allow it too (as well as the files’). In my case, this was a bit easier to do, because I was able to add the userid which MPD runs under, to my personal group, which has the same name as my personal userid.

If all this fails in spite of the attempts described, there’s another angle to consider. Some Linux systems may mount a specific storage volume with ‘fuse’, and, in user-mode! When that happens, no other user will have access to the mounted folders, not even root, and not even, if the individual directory permissions seem to give access. What can happen is, that certain types of mounts are constrained by access restrictions, which those per-folder or per-file permission bits don’t show.

If individual folders and files are set ?rwxrwx— BTW, where the ‘?’ could either be a ‘-‘ for a file, or a ‘d’ for a directory, then even root may not be able to access them.

Just as a precaution: You do realize that you need for ‘MPD‘ to have access, not Cantata! ‘Cantata’ is just a GUI to remote-control ‘MPD’, and such GUIs should not be run as root anyway.

Dirk

1. Riccardo Wanke says:

Hey Dirk,
thank you for your answer. Actually, I solved the problem! I extended the permission to all subdirectories and files…

yes.
Simple.

Thanks
R

2. Chris says:

Hi. New convert to MPD+Cantata here and ran across your post.

Sounds like you hit the same problem/confusion that is in front of my right now.

I’m coming from Clementine where I usually just add 2 folders. The one that’s an archive of everything I want to keep, and the one that I’ve put recent stuff in, that I’m still evaluating.

Apparently that doesn’t apply in the mpd world.

But sorry but you lost me as soon as you said “the author mentioned above…”

My headache might be putting me at a disadvantage here but can you possibly clarify a bit?

All I want to do is have Cantata / MPD have a database consisting of everything in 2 folders (each from 2 separate USB-mounted drives but that should be beside the point, I hope).

As things stand right now, I had kept trying to add collections, and lost all music altogether until I realized I had to go back to the default collection, if that makes any sense.

Thanks!

1. Dirk Mittler says:

I think that there might be a basic misconception, about what, exactly, MPD is. It’s not really meant to act as a drop-in replacement, for music-playing software such as Clementine. There exist appliances which have embedded computing systems. Those computing systems are usually much weaker than a full-blown, modern PC would be. But one such appliance will play relaxation music across a room. Kind of like Alexa, but retro.

One of the nice things which MPD is compatible with is “Calm Radio” – a paid-for service. They happen to offer their content on a Sonos. But, I wanted it to play from my PC.

Cantata is not a Music-player application. It’s a graphical way to control MPD. It’s nuts and bolts.

The simple fact that you’re trying to use it as a replacement for Clementine is already a sign, that it’s not the right tool for you. You need to set up directories that potentially do not belong to any user, and permission bits. The graphical style of Cantata gets nullified by the nature of the daemon it’s meant to control.

Sonos could contain MPD, but cannot contain Cantata.

Dirk

1. Chris Cortese says:

Sorry I’m replying almost 2 months later, but I just now happened to be checking my spam folder for something (which I almost never do) and saw your reply to Riccardo there. So probably your earlier reply went there, which is strange because gmail doesn’t give me too many spam false positives.

Thank you for the detailed reply, belatedly.

Besides Cantata I was on a bit of a mission to streamline my Arch Linux setup particularly by eliminating unnecessary software and dependencies.

After running Cantata/MPD with just my one main music directory (and not including my “new music” directory), I decided to be lazy and return to Clementine.

However, I am still now using MPD w/ncmpcpp about 50% of the time and Clementine the other 50%.