January 24th, 2013Top StoryTurn a Raspberry Pi Into an AirPlay Receiver for Streaming Music in Your Living RoomBy Thorin Klosowski Click to view Few things are better than kicking back on the couch and streaming your favorite album wirelessly to your stereo from your phone. It's a remarkably easy thing to do with AirPlay, but if you don't want to pay for Apple's solutions, a $35 Raspberry Pi does the job remarkably well. Check out the video above for a quick demo of what this project entails, and what you'll get with the final product. With a few tweaks to your initial Raspberry Pi installation, you can turn it into an amazing little device that can receive audio from any AirPlay-compatible device. That means wireless streaming to any speakers you have in the house. Music in the video by Comfort Fit and Jonathan Coulton. It's Raspberry Pi week at Lifehacker, and all week we'll be showing you some cool DIY projects you can put together with this little miracle of a device. If you haven't bought one yet, check out our introduction to the Pi to learn more about what it is, what you'll need, and the cool stuff you can do with one like setting up a personal VPN and turning it into an XBMC media center. What You'll NeedGetting the AirPlay receiver up and running on the Pi is easy, but you'll need a few materials first. Here's what you need to pick up:
What You Will (and Won't) GetThe Raspberry Pi makes a fantastic little AirPlay device. When you're done, you'll have a small box connected to your stereo that functions similar to AirPlay-enabled speakers. When it's plugged in and booted up it will automatically load everything necessary to start AirPlay with no need for an external monitor or keyboard. Essentially, it lets you stream music to any speakers you have sitting around for less than half the price of an AirPort Express, and you can still use it for any other Raspberry Pi project you want to take on. That's a serious win-win. However, the Raspberry Pi doesn't currently support AirPlay Mirroring to send video content. Still, what's nice about using the Raspberry Pi as an AirPlay device for your speakers is that you can continue to use it for any other project you like. Step One: Hook Up and Configure the Raspberry PiThe AirPlay function works with the Raspberry Pi installation of Raspbian. You can follow our guide for getting started with the Raspberry Pi to get Raspbian installed. If you want the AirPlay receiver to start automatically without the need for a keyboard or monitor, we need to set Raspbian to login you in automatically. During the setup process at the Raspi-config screen, change the "Start Desktop on Boot?" setting to yes. If you're already up and running, type this command into the terminal to load up Raspi-config again: sudo raspi-config Finally, the AirPlay functionality may require a few packages not initially included in your installation, so you want update your packages before you get started. Type this into the console: sudo apt-get update sudo apt-get upgrade The update might take a little while, so grab a beverage and sit back. Once you're booted up into Raspbian and everything is working properly, we can dig into setting up the AirPlay function. Note: It's possible to install everything you need using console commands, but we'll use the slightly easier Raspbian interface so that you can continue to use your Raspberry Pi for whatever else you like. Set Up Your USB Wi-Fi AdapterFirst off, we need to get the USB Wi-Fi adapter working. This is dead simple with Raspbian installed:
That's it for the Wi-Fi adapter. If you like, open up the internet browser Midori from the desktop to make sure the internet is working. Raspbian will remember your selection, so even if you disconnect the Wi-Fi adapter at any time during the process it will automatically load up again when it's connected to the Pi. Set Up Your Sound CardNext up we need to get the sound card up and working. First off, connect your USB sound card into the Raspberry Pi, and hook it up to your stereo with the 3.5mm audio cable (or plug in headphones so we can test to make sure it works). Now, we're going to use a terminal command to select it. Open up LXTerminal from your desktop and type in the following command: aplay -l Your USB card should display as something like, "card 1: set [device name], device 0: USB Audio." That means it's recognized by the Raspberry Pi. Now we need to test the sound. Type: Alsamixer This loads up the software to test the audio output. Press F6 to change the output type and select your sound card. Now we need to test the output: speaker-test You should hear a tone from your speakers verifying the USB sound card is working. Finally, Raspbian doesn't automatically load the USB sound card when it boots like it does the Wi-Fi USB adapter. This means we have to edit the the configuration file. Type the following: cd /etc/modprobe.d sudo nano alsa-base.conf This opens the alsa-base.conf file. Scroll down near the end of the file and look for this line: options snd-usb-audio index=-2 Comment that line out with a "#" symbol at the start of the line. Hit Ctrl+X to save and exit. Now your sound card and Wi-Fi adapters will both work automatically every time you start the Pi. Install the Shairport AirPlay EmulatorShairport is the software that actually makes AirPlay work, and it takes a little while to get it all set up. It's not a difficult process, but you do want to give yourself about 30 minutes because it requires a lot of downloading and installing of software. First off, we need to install a few things before we can get Shairport. Type this into the console: sudo apt-get install git libao-dev libssl-dev libcrypt-openssl-rsa-perl libio-socket-inet6-perl libwww-perl avahi-utils libmodule-build-perl Let this process run for a little while. When it's complete, we need to install an update so Shairport will work with iOS 6 (you can skip this step if you're not on or plan to upgrade iOS 6): git clone https://github.com/njh/perl-net-sdp.git perl-net-sdp cd perl-net-sdp perl Build.PL sudo ./Build sudo ./Build test sudo ./Build install cd .. Once the iOS 6 module is installed (give it a little while), it's finally time to get Shairport installed. from your home directory type: git clone https://github.com/hendrikw82/shairport.git cd shairport make Now, let's run Shairport: ./shairport.pl -a AirPi This command starts Shairport with your Raspberry Pi named "AirPi" (you can change it to whatever you want). Grab your iOS device, pick the music app of your choice, and tap the AirPlay button. You should see "AirPi" listed as an output device. Tap that, and the music should start streaming out of your USB sound card within a couple seconds. But we're not done yet. Shairport doesn't automatically load when you start your Raspberry Pi, and since we want to make our AirPlay device work without any peripherals we need to do one more step. From your home directory, type: cd shairport make install cp shairport.init.sample /etc/init.d/shairport cd /etc/init.d chmod a+x shairport update-rc.d shairport defaults Finally, we need to add Shairport as a launch item. Type: sudo nano shairport This loads up Shairport file we need to edit. Look through the file for the "DAEMON_ARGS" line, and change it so it looks like this: DAEMON_ARGS="-w $PIDFILE -a AirPi" Save the file (Ctrl+X), and you're all set. Shairport should launch on startup every time. You can now move the Raspberry Pi anywhere you like and do whatever else you want with it. As long as the USB sound card and Wi-Fi adapter are plugged in, they'll load up when you turn the Raspberry Pi along with Shairport. That means you don't need a monitor, keyboard, or mouse next to your stereo for it to work. Once you're all set up, all you need to do to use the AirPlay function is plug the Raspberry Pi in, and wait for it to boot up. Once the operating system loads (it takes about 30-40 seconds usually), you can instantly and easily send all your music through the Raspberry Pi. Take It FurtherThe AirPlay functionality is just the tip of the iceberg. You can do a lot more with it once the functionality is set up. Here are just a few different ideas that expand the AirPlay functionality in the Raspberry Pi way past the AirPort Express:
A big thanks goes out to Jordan Burgess and Trouch for their guides to getting Shairport repositories installed and adding iOS 6 support. Click to viewClick to view |
|
No matter how carefully you plan your goals they will never be more that pipe dreams unless you pursue them with gusto. --- W. Clement Stone
Thursday, January 24, 2013
Turn a Raspberry Pi Into an AirPlay Receiver for Streaming Music in Your Living Room
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment