Pages

Sunday, September 2, 2012

Raspberry Pi & Spotify

Like other people we have a radio in the kitchen. However, ours is so old that you don't want to touch the volume control, because the random noise produced by doing so gives you a headache. Now, since I am a proud Raspberry Pi owner as well, I had this idea to use it as a spotify-kitchen-radio, meaning: have the RPi in our kitchen, connected to the LAN, some speakers plugged in and spotify running. However, there is no ARM-build spotify client, so it's not that easy. However, there is an ARM version of libspotify, that provides an API to spotify's service (you will need a premium account, which I recommend to everyone anyways - spotify is really awesome and its only 10 bucks per month). So here are some comments, preliminary results and some advice on how to make the spotify API work on your RPi (and at least being able to play your playlists) 

1.) If you use Raspbian - that won't work, since it is build using the hard float ABI capability of the ARM. If you try to install libspotify and make the examples work, eveything seems find at the beginning, but then you get an error like
libspotify.so.12.1.51: cannot open shared object file: No such file or directory
This is due to the fact that libspotify seems to have been build using soft-float ABI. As long as spotify doesn't release a hard float build, you will have to go to step 2. This insight is the crucial part of the game here (and a "cannot open shared object file" error is not an obvious hint in this direction) 

2.) If you want libspotify to work, you will have your RPi running the soft-float build of Raspbian, also available here: http://www.raspberrypi.org/downloads 

3.) Once you have that, things are straight foward. Download libspotify from the spotify developer page and follow the instructions in the readme. This is also where you will need a spotify premium membership in order to get an appkey. 

4.) In order to test it, you can use the jukebox example. Simply, after building it, run jukebox/jukebox. It will ask you for your login credentials and a playlist to run. If you don't hear anything, try another playlist. This "terminal version" of spotify seems to not tell you when a title is not available anymore, but instead simply keeps silent. 

Advice: The jukebox example requires you to have alsa installed and *configured*. So, before testing the spotify api and complaining that it does not play any sound, you should configure the sound card. See e.g. here or simply google for raspberry pi and alsa Have fun! 

PS: As a kitchen-radio this is still a bit uncomfortable. What I would ultimately like to have is a LAN-internal web-interface to the pi and libspotify, so that from every computer/tablet/smartphone in the LAN, I can access the local web-interface and search for/play titles, artists, albums ...

5 comments:

  1. Yes - this is just what I am looking for too!

    ReplyDelete
  2. I haven´t tried that but maybe control through squeeze / app is possible. Another way would be to make the raspberry a wlan hotspot but then its range is pretty short then, about 5m.

    ReplyDelete
  3. There's a suggestion on the Spotify forum where one can vote for Spotify to compile a hard-float ARM version of libspotify (as discussed in step 1 above). I think this could make life easier, as we could use the hard-float Xbian. To vote, go to the idea here: http://community.spotify.com/t5/Spotify-Ideas/armhf-Spotify-library-for-DIY-projects/idi-p/140972, log in with your Spotify account and give it some kudos.

    ReplyDelete
  4. You can take a look to mopidy (http://www.mopidy.com/) which provide a MPD server based on libspotify. You can after use a mpd client on any of your other device (smartphone, pc, ...)

    ReplyDelete