শুক্রবার, ২৫ জানুয়ারী, ২০১৩

Turn a Raspberry Pi Into an AirPlay Receiver for Streaming Music in Your Living Room

Turn a Raspberry Pi Into an AirPlay Receiver for Streaming Music in Your Living RoomTurn a Raspberry Pi Into an AirPlay Receiver for Streaming Music in Your Living Room 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 Need

Getting 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:

  • A Raspberry Pi: If you're not sure where to buy one, check out our introduction to the Pi for more info.
  • An HDMI or composite video cable: You'll need this cable to connect your Raspberry Pi to your television or monitor temporarily to get the Raspberry Pi set up. You can get these cheaply at Monoprice if you don't have one already.
  • An 8GB Class 10 SD card (or better) and a card reader (if you don't have one built into your computer): You can go smaller or slower, but an 8GB Class 10 card will get you the best performance, and they're pretty cheap. Most SD cards will work, but some aren't compatible and will therefore cause issues. You can find out which cards are compatible, or locate a place to buy a compatible card with an operating system pre-installed, on this page.
  • A USB keyboard and mouse: Any standard USB keyboard or mouse will do. You'll only need these for the setup process, so whatever you have attached to your computer right now should do the trick.
  • A good quality, micro USB power supply that can provide at least
    700mA at 5V
    : Most modern smartphone chargers supply 700mA at 5V, but not all do. Check the bottom of your charger and look for a block of text. You'll see its output values in that text which may read 0.7A instead of 700mA). If it offers at least that much power, you're probably good to go. Just don't use a poor quality charger or you may run into problems.
  • A 3.5mm stereo audio cable : You need this to run the Raspberry Pi into your stereo.
  • Wi-Fi USB Adapter: The Wi-Fi USB adaptor makes it possible to send your AirPlay music from your iOS device to your Raspberry Pi. I used this $10 Edimax one and it worked fine, but you can find a full list of compatible adapters here.
  • USB Sound card: The audio output on the Raspberry Pi isn't that great, so if you want to beef up your sound you should grab a USB soundcard. You can find a list of compatible cards here. I just used this cheap, $5 generic sound card, but a USB DAC will really clean up the sound nicely.
  • Stereo (and speakers): Obviously you'll need to send your sound somewhere, so you'll need a stereo and speakers that allow an audio input.
  • An iOS Device or Computer: You'll need an iPhone, iPod Touch, or iPad, or computer with iTunes installed as a source for your music. Theoretically an Android device with software like doubleTwist would also work, but we haven't tested it.

What You Will (and Won't) Get

The 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 Pi

Turn a Raspberry Pi Into an AirPlay Receiver for Streaming Music in Your Living RoomThe 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 Adapter

Turn a Raspberry Pi Into an AirPlay Receiver for Streaming Music in Your Living RoomFirst off, we need to get the USB Wi-Fi adapter working. This is dead simple with Raspbian installed:

  1. Connect your USB Wi-Fi Adapter to the Pi if it isn't already.
  2. Open the WiFi Config application on the desktop.
  3. Select your adapter from the drop down list.
  4. Sign into your home network.

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 Card

Next 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 Emulator

Turn a Raspberry Pi Into an AirPlay Receiver for Streaming Music in Your Living RoomShairport 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 Further

The 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.

Source: http://feeds.gawker.com/~r/lifehacker/full/~3/7fu3kqsfDrE/turn-a-raspberry-pi-into-an-airplay-receiver-for-streaming-music-in-your-living-room

big east tournament ashley olsen new apple tv sun flare love hewitt new ipad solar flare

কোন মন্তব্য নেই:

একটি মন্তব্য পোস্ট করুন