一键给 Raspberry Pi 安装 AirPlay

rpi_meet_airplay

之前在 Twitter 上面有人抱怨说 RPi 不适合拿来用,太麻烦玩不起,所以特此写了个脚本,一键安装开源的 ShAirPort 到你的 Raspberry Pi 上,省下个 AirPort Express 的钱,何乐而不为呢?

快速安装指南:
首先,参照这个官方指南设置你的 RPi 并安装好 Raspbian 系统。
然后,SSH 到你的 RPi 上,使用用户名 "pi" 和密码 "raspberry" 登陆。登陆后运行:

1
2
3
4
wget http://u.billgong.com/AirPlay4RPi
unzip AirPlay4RPi
chmod +x shairport_installer.sh
./shairport_installer.sh

并按照屏幕上的提示安装即可

安装后,ShAirPort 的 Daemon 将在每次启动的时候自动运行,使用你的设备连接到 "AirPlay-RPi" 这个服务器上,音乐就会从 RPi 的耳机孔中播放出来。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/bash
 
# ShAirPort for Raspbian 一键安装包
# By Bill Haofei Gong on 15th Jan, 2013
#
# 感谢所有此脚本中所有引用的开源代码的作者。You guys rock!
# 同时感谢 http://trouch.com/2012/08/03/airpi-airplay-audio-with-raspberry 的作者,以及指出 iOS 6 兼容性解决方案的评论者 Chris
 
# 升级并清理 Raspbian
sudo apt-get update && sudo apt-get dist-upgrade -y
sudo apt-get autoremove -y && sudo apt-get autoclean && sudo apt-get clean
 
# 设置音频输出为耳机插孔,取消静音并将音量调至最大
sudo amixer cset numid=3 1
amixer sset Master unmute
amixer sset Master 100%
 
# 安装依赖包
sudo apt-get install git libao-dev libssl-dev libcrypt-openssl-rsa-perl libio-socket-inet6-perl libwww-perl avahi-utils libmodule-build-perl -y
 
# 从Git克隆源码
git clone git://github.com/njh/perl-net-sdp.git perl-net-sdp
git clone git://github.com/hendrikw82/shairport.git shairport
 
# 编译并安装依赖的组件
cd perl-net-sdp/
perl Build.PL
./Build
./Build test
sudo ./Build install
cd ..
 
# 编译ShAirPort,测试运行并安装
cd shairport/
make
echo "现在,测试运行将要开始!"
echo "请将你的AirPlay设备连接到Raspberry Pi所在的同一网络中,然后查看AirPlay列表中是否存在一个名为\"TestPort\"的服务器。连接到这个服务器并随便播放一个音频文件测试功能是否正常。别忘了将你的音响插到Raspberry Pi的耳机孔上。"
echo "在试运行成功后,请按下 \"Ctrl+C\" 来继续安装。"
./shairport.pl -a TestPort
sudo make install
sudo cp shairport.init.sample /etc/init.d/shairport
sudo sed -i 's/DAEMON_ARGS=\"-w \$PIDFILE\"/DAEMON_ARGS=\"-w \$PIDFILE -a AirPlay-RPi\"/g' /etc/init.d/shairport
sudo update-rc.d shairport defaults
sudo service shairport start
 
# 安装完毕
echo "###############################################"
echo "# 安装结束!                                  #"
echo "# 现在你应该可以上找到一个名为\"AirPlay-RPi\"的 #"
echo "# AirPlay服务器,将设备连接到这个服务器上即可 #"
echo "# 通过Raspberry Pi播放音乐了!                #"
echo "# 建议你运行\"sudo shutdown -rf now\"重启RPi    #"
echo "###############################################"

狂击这里下载脚本

3 Comments

  1. FW36刘宣麟 says:

    这个可以airplay视频吗?

Leave a Reply to FW36刘宣麟 Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.