How to stream Apple Music to a Raspberry Pi

With the recent release of Apple Music I wanted to play music through some speakers in my home that had a bit more oomph than my laptop. Unfortunately I don’t have a hi-fi system or any speakers, just an Xbox One and the TV, I do however have a spare Raspberry Pi.

Kodi (née XBMC) supports Apple’s AirPlay protocol out of the box so I just needed to get it running on the Raspberry Pi, which was a little more fiddly than I expected. I tried flashing an SD card with the images provided on the Raspberry Pi Foundation’s website, but none of them worked – this was probably more due to the very old laptop I was using to flash the card – in the end I found a much simpler solution which doesn’t require using the command line or flashing SD cards.

Instead you can use the NOOBS Lite GUI installer to setup OpenELEC on the Pi, which is an version of Kodi optimised to run on low power devices such as the Raspberry Pi.

For this method you will need: A blank SD card, a Raspberry Pi with an Ethernet port, an Ethernet cable, a HDMI cable and a USB keyboard or mouse. Note that for the initial setup you will need the Ethernet cable for a wired internet connection, after setup you can switch to WiFi.

  1. Download NOOBS Lite.
  2. Connect the SD card to your computer.
  3. Unzip the files and copy them across to the SD card.
  4. Disconnect the SD card from your computer and insert it into the Raspberry Pi.
  5. Connect the Ethernet, HDMI, USB keyboard/mouse and power supply to the Raspberry Pi.
  6. The Raspberry Pi should boot up and display a list of operating systems to install.
  7. Select ‘OpenELEC’ from the list and click ‘Install’ or press I if you only have a keyboard.
  8. Once the latest version of OpenELEC has been downloaded and installed you are almost ready to go, the Pi should automatically restart and launch Kodi.
  9. Navigate to System > Settings > Services > AirPlay, and make sure the option ‘Allow Kodi to receive AirPlay content’ has been checked.
  10. If you have a USB WiFi adapter you can now connect it to your network by going to System > OpenELEC > Connections, then select your network from the list and enter the password.

After that’s all setup you should see Kodi appear in the AirPlay list on your Mac or iOS device and you can stream everything to your Raspberry Pi. As you are using AirPlay the Pi can also receive video and images from your devices simultaneously. I was able to stream music from my iPhone whilst I browsed photos from my iPad connected at the same time, pretty nifty!

Whilst this is all a bit more fiddly than just getting an Apple TV box, it’s a lot cheaper – you can pick up a Model B+ for around £16.

→ arkOS

arkOS is a system for securely self-hosting your online life from the comfort of your home.

It will allow you to easily host your own website, email, “cloud” and more, all within arm’s reach. It does this by interfacing with existing software and allowing the user to easily update and change settings with a graphical interface. No more need to depend on external cloud services, which can be insecure “walled gardens” that require you to give up control over your data.

What is arkOS? – arkOS FAQ

Interesting idea, kinda like Windows Home Server for Linux.

→ Upstagram – Pi over Paris

The colorful flying house from the movie UP! recently crossed the sky above Paris, just between the Eiffel Tower and the Sacré Coeur! On board, an open-source electronic device, a Rapsberry Pi, publishing live pictures on Instagram.
Upstagram – HackerLoop

This is a great little hack.

Coder for Raspberry Pi

Coder is a free, open source project that turns a Raspberry Pi into a simple platform that educators and parents can use to teach the basics of building for the web. New coders can craft small projects in HTML, CSS, and Javascript, right from the web browser.

Coder for Raspberry Pi

Looking forward to trying this out, previous versions of Chromium have been doggedly slow on the Pi.

Edit: Bummer, looks like it’s just running a Node.js webserver, not Chrome itself.

Audio on the Raspberry Pi with Node.js

I recently wanted to play some audio through the Raspberry Pi programatically, but primarily being a web developer I wasn’t really sure how to approach the task. I can manipulate the DOM all day without breaking a sweat, but without the Web Audio API or <audio> element I was a bit stumped. Previously I’ve played around with Node.js on the Pi, but I didn’t think it would have any packages for audio and thought I’d have to use Python or Scratch which are well supported on the Pi.

Turns out you can use Node and it’s pretty simple too. I based my implementation on this Gist:

https://gist.github.com/TooTallNate/3947591

If you’re not familiar with Node, I’ll explain a little about what this does. The first few lines are importing all the modules we’ll need: fs the filesystem module baked into Node, which will read in the MP3. Next lame which will decode the MP3 into raw PCM data. Finally speaker that simply outputs PCM audio data you feed it.

In this example the file is passed to Node as an argument when the script is run from the command line, like so:

$ node mp3player.js sounds/file.mp3

The MP3 is piped through lame and then as it is decoded output to speaker. This worked right out of the box on my Mac, but a bit of fiddling was required to get it working on the Pi.

First lame needed to compile a bunch of native extensions for the MP3 decoding, this wasn’t really a problem as it compiled cleanly the first time, it just took a while.

Second, the program ran without error, but I couldn’t hear anything. Turns out the Pi can output audio over HDMI or the 3.5mm stereo jack, but in my case it was sending the audio over HDMI, even though the monitor connected didn’t have speakers. Fortunately you can override the output and the following command will switch it to the stereo jack:

$ amixer cset numid=3 1

After that it worked a treat, playing crisp and clear sound.

I didn’t realise it at the time, but I’ve just noticed that the Gist and modules are all by Nathan Rajlich, nice work!