I’ve started using Spotify a lot more lately, so I’ve decided to switch to Mopidy instead of mpd at least for the time being. Mopidy is a music and http server which allows plugins like ones that integrate spotify music into you library. Mopidy uses mpd as its backbone which makes it sort of familiar.
mpc can still be used to control the music in command line which means it will still work with my lircrc commands. What made mopidy unfamiliar to me other than its configuration was that it uses gstreamer to control the playback. In the past, I had some trouble getting alsa output with hardware mixing which my usb dac supports. I believe there was an update recently that allows better alsa integration, whoo hoo! I’m not sure if the additional gstreamer layer makes the playback any less audiophile-like. But from what I’ve read throughout the internet, gstreamer, which is used with a lot of linux music players, can play bit perfectly.
Installing Mopidy on Linux Mint is a little less straightforward compared to mpd. You can find the instructions here, but I will summarize all the steps I used to get it working for my particular set up.
You’ll need to first add the Mopidy APT archive to your system since Mopidy is not included in any of the built-in Ubuntu/Mint repositories.
Add the PGP key.
wget -q -O - https://apt.mopidy.com/mopidy.gpg | sudo apt-key add -
Edit the sources.list file:
sudo nano /etc/apt/sources.list
Then add the following lines:
# Mopidy APT archive deb http://apt.mopidy.com/ stable main contrib non-free deb-src http://apt.mopidy.com/ stable main contrib non-free
sudo apt-get update && sudo apt-get install mopidy
Now let’s install the spotify and the alsa-mixer plugin.
sudo apt-get install mopidy-spotify mopidy-alsamixer
Mopidy by default uses a software mixer to control the volume, but that isn’t very audiophile. The alsa mixer plugin allows you to use the
alsamixer command which adjusts hardware volume like the one on my hifimediy USB DAC. Which also means whenever you change the volume using a mopidy/mpd front end like MPaD, it will use the hardware mixer instead of the software mixer.
The Mopidy developers recommend running mopidy by running it in the foreground (not sure why), like just typing the
mopidy command, so a lot of the configuration steps are based around that. But if you want to run it like service or in the background the steps are a little different which wasn’t super obvious to me. The service instructions are in the documentation, but I just didn’t know where to look.
First edit the mopidy configuration file that’s used for running mopidy as a service.
sudo nano /etc/mopidy/mopidy.conf
Then fill the file with this:
[logging] config_file = /etc/mopidy/logging.conf debug_file = /var/log/mopidy/mopidy-debug.log [local] enabled = true data_dir = /var/lib/mopidy/local media_dir = /var/lib/mpd/music playlists_dir = /var/lib/mopidy/playlists scan_timeout = 5000 [http] hostname = :: [mpd] hostname = :: zeroconf = Mopidy on $hostname [audio] mixer = alsamixer output = alsasink device=hw:1,0 [alsamixer] card = 1 control = PCM [softwaremixer] enabled = false [spotify] enabled = true username = spotify_username password = spotify_password bitrate = 320
Explanations of some of the configurations.
[local] enabled = true data_dir = /var/lib/mopidy/local media_dir = /var/lib/mpd/music playlists_dir = /var/lib/mopidy/playlists scan_timeout = 5000
media_dir = /var/lib/mpd/music is where all my local music on my nfs share is mounted to.
scan_timeout = 5000 is the amount of time in milliseconds mopidy will scan a song for its info before timing out. By default it was set to 1000ms. Since my music is on a share, it seemed like that may have been too short, so I switched it 5000.
[http] hostname = :: [mpd] hostname = :: zeroconf = Mopidy on $hostname
The hostname is the address the http and mpd servers bind to.
:: seems to be foolproof.
[audio] mixer = alsamixer output = alsasink device=hw:1,0
Here we are changing the mixer from software to alsamixer (hardware).
We also have to change the gstreamer sink to alsasink. It won’t know which device to use, so I’ve specified mine which is located at
hw:1,0. You can find yours by using the
aplay -l command.
[alsamixer] card = 1 control = PCM
We also need to let it know which card to use for the mixing, the “1” part of
[softwaremixer] enabled = false
We should disable the software mixer, just in case.
[spotify] enabled = true username = spotify_username password = spotify_password bitrate = 320
Enter your spotify credentials. This won’t work if you don’t have a premium account. Also set the bitrate to 320 so you can use the highest quality spotify offers.
Running Mopidy as a service.
Activate the service. When it asks if you want to start Mopidy at boot, choose yes.
sudo dpkg-reconfigure mopidy
After rebooting, Mopidy should be running in the background. You can now check the configuration settings you made by using this command:
sudo service mopidy run config
It should show all the configurations that you made in
You can start, stop, and restart mopidy manually by using these commands:
sudo service mopidy start sudo service mopidy stop sudo service mopidy restart
To scan your local library use the following command:
sudo service mopidy run local scan
This might take a while depending on how large your local library is.
After everything is running, you can check the logs using one of the following commands to see what’s mopidy is doing:
cat /var/log/mopidy/mopidy.log tail -f /var/log/mopidy/mopidy.log
cat will give you a snapshot of your log when you ran it.
tail will pipe any changes that happen to your screen directly.
Most mpd clients should work with Mopidy. I’ve tried
ncmpcpp, and MPaD/MPoD.
ncmpcpp is a little sluggish when you try to scroll through your music, so I’ve decided not to use it.
How do you find Spotify music? Your mpd client’s search feature should search the spotify library at the same time as your local library. Also, any playlists you create or follow in Spotify should show up in your mpd client’s playlist section. I have noticed that it might take a long time before your initial set of playlists pop up in your mpd client. Updates to your playlists work more quickly though.
I’ve installed a couple http clients so people who come over can just go to the site and control what music is playing. That’s the plan anyway. Mopidy has made it relatively painless to install these clients.
Installing Moped is fairly straightforward.
sudo pip install Mopidy-Moped
Installing MusicBox is very similar to Moped.
sudo pip install Mopidy-MusicBox-Webclient
I tried installing Apollo which seems like a really slick looking front end, but I just could not get it to work. It is not so straightforward like the above two.
Viewing your new http clients
You can visit the http client by entering your mopidy server’s address and the default port. Mine is:
This will show links to each of the http clients you just installed.
Or you can use these:
High resolution ALAC
Mopidy uses gstreamer 0.10 which has a little bug playing back ALAC files. For some reason, it doesn’t want to pick up the sample rate of the file. So if a file is a 24 bit 96khz file, it will actually play it back as 24 bit 44.1khz. It doesn’t resample the file; it will just play it back about half speed. This does not happen with FLAC files though. I have read that Mopidy will move to gstreamer 1.0 which doesn’t have this problem, but the original post was from 2012, so who knows when it will actually be implemented. There is some recent activity on the thread, so that’s good.
My Spotify playlists disappear often, and they don’t come back for a while. It just happened to me again now.