What is Freeside?

Freeside is a Georgia nonprofit corporation, organized to develop a community of coders, makers, artists, and researchers in order to promote collaboration and community outreach. Learn more »

Raspberry Pi Headless Media Center

Greetings fellow Raspberry Pi enthusiasts. I have something pretty cool to share with you today. I've been wanting to use the Raspberry Pi for a media center since I first heard about it. When Newark finally told me I could order the Pi I jumped at it chance and then promptly left town on a family vacation. My nephew Isaiah, who I met up with in Alaska while we were on vacation, discussed the media center project and how to implement it. Upon his suggestion we settled on running VLC. I had assumed we would have to get some webserver up and running and figure out how to slave VLC to our wishes but that is largely built in already. It is called the VLC Web Interface (or VLC http interface). That made this project all the more simple.

Below is the process to install it. This process assumes you have a freshly flashed Raspbian Wheezy (7/15) image that has NEVER BEEN BOOTED BEFORE. This made the most sense for us as we assumed you would plop this guy down somewhere and not use it for anything else.
  1. Take a freshly flashed Raspbian Wheezy imaged SDCARD and put it in your Rπ
  2. Make sure your WIFI adapter is NOT plugged in.
  3. Plug in keyboard
  4. Plug in Ethernet cable connected to the Internet
  5. Plug in Rπ
  6. Raspbian will boot up to the setup screen
    1. expand_rootfs
    2. configure_keyboard
      1. Select keyboard that works for you (default is UK which is hard to use with a US keyboard) Images of this process are at the bottom of this post (its sort of long and tedious).
    3. change_locale
    4. change_timezone
    5. ssh
      1. enable SSH Server (not necessary but useful since its headless)
    6. boot_behavior
      1. So NO. You want to disable booting to the desktop
  7. Reboot
  8. Login as root. Type "root" at the login prompt.
  9. Enter the commands below. (downloads and executes an installer script written by my nephew)
    wget db.tt/rDy1S8Ga -O install.sh
    source ./install.sh
    It will prompt you the following things:
    Press zero to set output to auto, press 1 to force headphone jack, press 2 to force HDMI.
    I recommend you select 1 if you plan to use the headphone jack.
    Would you like to setup the GPIO relay [y/n]?
    Click Y if you want GPIO25 (pin 22) to go HIGH (3.3V) when VLC is playing. Pin 22 is positive and Pin 6 is GND. The numbering system is strange because it starts at 1. You want the third pins from the top and bottom on the outside. Refer to the photo below. SSR available at Amazon.com
  10. Would you like to install rtl8188cus WIFI drivers [y/n]?
    This is the driver for the WIFI adapter I selected. Available at Amazon.com
    This driver installer was acquired from the Rπ forum and used with permission.
  11. At this point the install actually begins. VLC takes a long time to download and install. Then, if you selected the WIFI drivers it will ask you a bunch of VERY IMPORTANT questions and PROMPT YOU WHEN IT IS SAFE TO INSERT YOUR WIFI ADAPTER. Please read and follow along. I found that if it pauses for a long time while it prompts you to wait for the adapter to blink and connect  a quick re-plugging in of the adapter gets the system running again. The WIFI driver script ends asking you if you would like to upgrade your entire Rπ. I say no.
  12. Unplug your ethernet cable (if you are using wifi).
  13. Reboot.
  14. Boot up screen will tell you what the new IP address is on Wifi. make a note of it. You can then use this address to talk to your Rπ from local devices on the network. You can setup a static IP if you desire by going to /etc/networks/interfaces and changing the
    iface wlan0 inet dhcp
    iface wlan0 inet static
    address *your ip*
    gateway *your gateway ip*
    wpa-ssid "*your SSID*"
    wpa-psk "*your password*"
You can now find you VLC running at http://*ip address*/. If you want to see if from the actual Rπ you need to go to http://localhost:8080 but we went through the effort of updating the IPTABLES to forward port 80 to port 8080. The /home/pi folder is the default place it looks for music.

The GPIO stuff works by running a script that checks the VLC status stream and turns the pin on or off as necessary. I did this with one long shell command the executes every 300ms. There are no doubt many ways to do this, but I always liked AWK and | so that's how I did it (its below). You can find all scripts we wrote to make this work in the /root folder.

wget -qO- localhost:8080/requests/status.xml | awk '/<state>/ {if (index($0,"playing") > 0 || index($0,"paused") > 0) {print "echo "1" > /sys/class/gpio/gpio25/value"} else {print "echo "0" > /sys/class/gpio/gpio25/value"}}' | bash

One thing I should mention is that depending on your network speed, you may want to increase the buffering cache so you do not get skips during streaming playback. This is done by modifying the /etc/init.d/rc.local. Add the two caching arguments you see below (to the line starting vlc you'll find it in there somewhere)
su - vlc -c "vlc --intf http --daemon --disc-caching=20000 --network-caching=20000

These are some screen shots from the initial config. I found the keyboard part sort of confusing.


John Grreen said...

Thanks so much for this guide. Worked perfectly! Any idea, though, why .pls files (i.e. the stream from indiepoprocks internet radio station) won't show up when browsing the file system for media? I checked that it is an allowed file type in the internals of the vlc distro that we're using here... And it is. I wonder if it is a limitation with the front end of the interface that you built?

John Grreen said...

oh wait! I figured it out. I needed to edit controlers.js in /usr/share/vlc/lua/http/js according to the commit here: http://git.videolan.org/gitweb.cgi/vlc/vlc-2.0.git/?p=vlc/vlc-2.0.git;a=commitdiff;h=9855165f8168f0db54852d208fd8be8a3e5cffb1;hp=ac7e319910923a63323728ce7ce999a52432c548

Post a Comment