Spotify + Raspberry PI

Posted by on Jun 22, 2014 in Sin categoría | No Comments


Hoy pude agregar otro uso a mi raspberry pi: servidor de spotify! Ya no necesito tener la compu prendida para escuchar música en el spotify, ahora solo conecto los parlantes a la raspberry y controlo desde mi celular lo que quiero escuchar.

Lo logré instalando mopidy con el mod spotify, siguiendo los pasos de este tutorial sacado de:



Turn your Raspberry Pi into a Spotify server

In this tutorial we will install Mopidy on our Raspberry Pi. This will allow us to use the Pi as a music server where we can access all of our local music files, as well as playlists from e.g. Spotify, and stream it directly to our TV or speaker system.

What is Mopidy?

Mopidy is a music server that can play music from a wide variety of sources, like your local hard drive, radio streams, Spotify, and SoundCloud. The nice thing about Mopidy is that it collects all of your music sources in one place. This makes it a perfect match for our Raspberry Pi.

Another cool feature is that when you search your library, it combines results from all music sources, and you can mix tracks from all sources in your play queue. That includes your playlists from e.g. Spotify, SoundCloud, or other available sources.

To control your Mopidy music server, you can use a wide variety of web clients, the Ubuntu Sound Menu, any device on the same network which can control UPnP MediaRenderers, or any MPD client.

There are MPD clients available for many platforms, including Windows, OSX, Linux, Android and iOS. We will look into some of these in the end of this article.

Using these clients, Mopidy allows you to control your music from any device. And if you make your Pi accessible from outside the LAN, you can literally control your music from anywhere in the world!


0. Add needed modules

As a first step we need to activate some modules to avoid potential problems during the installation. First, run the following command to activate ipv6:

sudo modprobe ipv6

Now open /etc/modules and add this to make sure modules are loaded on reboot:


1. Add the archive’s GPG key

Run the following command to add Mopidy’s GPG key:

wget -q -O - | sudo apt-key add -

2. Modify your sources.list

Add the following to /etc/apt/sources.list, or if you have the directory/etc/apt/sources.list.d/, add it to a file called mopidy.list in that directory:

# Mopidy APT archive
deb stable main contrib non-free
deb-src stable main contrib non-free

3. Install Mopidy and all dependencies:

sudo apt-get update
sudo apt-get install mopidy

4. Create the Mopidy config file

Now that we have installed Mopidy, it’s time to make some modifications to its config file. Right now we don’t have a config file, and we can either create on manually, or let Mopidy generate one for us that will contain all the default values. We are not stupid, so let’s do the latter.

In order to have Mopidy create the config file for us, we simply have to start Mopidy. If it cannot find a config file, it will create a new one at startup. The file will be created in ~/.config/mopidy/mopidy.conf.

Run Mopidy:


…and you should see something like this:

 INFO Starting Mopidy 0.18.3
INFO Loading config from: builtin defaults, /etc/xdg/mopidy/mopidy.conf, /home/pi/.config/mopidy/mopidy.conf, command line options
INFO Enabled extensions: mpd, http, stream
INFO Disabled extensions: local
WARNING Found local configuration errors, the extension has been automatically disabled:
WARNING local/media_dir must be set.
WARNING Please fix the extension configuration errors or disable the extensions to silence these messages.
INFO Starting Mopidy audio
INFO Starting Mopidy backends: StreamBackend
INFO Audio output set to "autoaudiosink"
INFO Audio mixer is using software mixing
INFO Starting Mopidy core
INFO Starting Mopidy frontends: HttpFrontend, MpdFrontend
INFO MPD server running at [::ffff:]:6600
INFO HTTP server running at

Stop the server with Ctrl-C.

Now we have the configuration file in place. If you want to, you can take a look at it to see how the default settings are. We will edit a few things later on.

6. Restart the system

Now we need to restart the system to make sure all the new modules and dependencies are working correctly:

sudo reboot
A very important note for RaspBMC users. Due to a dependency version problem that is caused when installing Mopidy, you might have to make some minor configurations for XBMC to start properly (this depends on your system’s version).If you notice that XBMC is not starting but gets stuck in a loop, you need to make these configurations. In short, what you have to do is the following:

Run the following command, and it should stop the loop and start up as normal:

sudo ln -sf /home/pi/.xbmc-current/xbmc-bin/lib/xbmc/system/ /usr/lib/arm-linux-gnueabihf/

Then you need to open /etc/rc.local and add the command to the end of the file to make it persistent on reboot. Now it will not complain anymore when you restart your system.

You can read more about it in this post.

7. Audio output

Once you have restarted the system, we can start making some changes to our settings.

By default the audio will output to HDMI, and if you want to change that we need to change this value in the amixer settings:

sudo amixer cset numid=3 1

The ‘1’ in the end indicates that we want the audio to output to analog. Other options for this value are:


You can test these settings by running:

aplay /usr/share/sounds/alsa/Front_Center.wav

… and you should hear a voice saying ‘front center’.

8. Install Spotify extension

After all the basic settings for Mopidy are in place, we can install the Spotify extension. This will allow Mopidy to connect to Spotify with your account and fetch all your playlists. Run the following command to install the extension:

sudo apt-get install mopidy-spotify

9. Edit the Mopidy conf

Now it’s time to make some modifications to the config file. Let’s open the  ~/.config/mopidy/mopidy.conf file again so we can add a few things.

Under the section [ audio], we need to change the output value:

[ audio]
output = alsasink

Remember to remove the ‘#’ from the beginning of the line. You can leave all the other values as they are.

We also have to add a new section for the Spotify extension. Add the following anywhere in the file:

username = yourusername
password = yourpassword

Next we will prepare Mopidy to accept client connections. Under the section [mpd], change hostname to :: and set a password:

hostname = ::
password = yourpassword

The change in hostname makes it possible for us to connect to Mopidy from any IP address, and not only from the Pi itself.

Leave the rest as default.

When you have done this we must restart Mopidy in order for it to load the new settings:

sudo pkill mopidy

Now you can see that Mopidy is also loading the Spotify extension, and you should also see that it’s loading all of your Spotify playlists.


Now that we’ve installed Mopidy, we can start playing around with different clients we want to use to connect to it. At this point you can connect any MPD client to Mopidy and control your music. There are a few you can choose from, and the official Mopidy site lists a few they recommend.

MPD Client

We have already prepared Mopidy to accept connections from MPD clients, so let’s start with that.

If you have an Android phone, you can download MPDroid from here.iPhone users can download MPoD from here.

In order to connect to your Mopidy server, make sure that your phone is connected to the LAN and simply input the IP of the Pi along with the password you set for the mpd connection in the Mopidy config.

Web client

You might want the option to connect to Mopidy through a web client, so let’s set that up as well. This means anybody can access it from a browser, which is nice if you have friends over and they want to search for a song from their phone or laptop.

There are a few HTTP clients for Mopidy that work really great. We will install Mopidy-Webclient by woutervanwijk, but you can use anyone you’d like.

Let’s get the client:

sudo mkdir -p /opt/webclient
sudo mv Mopidy-Webclient-master/flatclient/ /opt/webclient/
If you have problems getting the zip file due to an error like:

ERROR: The certificate of `' is not trusted.

Add the --no-check-certificate flag to the wget command

Now we need to edit the Mopidy config file:

vim .config/mopidy/mopidy.conf

Find the [http] section, and edit it to look like this:

enabled = true
hostname = ::
port = 6680
static_dir = /opt/webclient/flatclient

Restart Mopidy:

pkill mopidy

Now you are able to connect to Mopidy through your browser. Simply enter the IP of you Pi, and the port as specified in the config file (6680), e.g.

This was a rather long tutorial, but hopefully it was worth it. Don’t forget to share it if you liked it, and drop a comment if you have any question or need help with anything!

Share this Story

About Robin Bellini Olsson

Software engineer, big thinker, and co-founder of Noeit.
Political views: Android > iOS

Leave a Reply