以下說明怎麼安裝ShairPort讓Pi變成AirPlay裝置
1. 安裝ShairPort相依套件
pi@ShiunPiSnd ~ $ sudo apt-get install libssl-dev libavahi-client-dev libasound2-dev libao-dev avahi-utils
註: 由於筆者用的abrasive/shairport沒有使用到perl,所以不用特地去安裝perl相關套件
2. 建置並安裝ShairPort
# 下載ShairPort原始碼
pi@ShiunPiSnd ~ $ git clone https://github.com/abrasive/shairport
pi@ShiunPiSnd ~ $ cd shairport
# 檢查設定相依套件是否都安裝正確
pi@ShiunPiSnd ~/shairport $ ./configure
Configuring Shairport
OpenSSL found
libao found
PulseAudio or its dev package not found
ALSA found
Avahi client found
getopt.h found
CFLAGS: -I/usr/include/alsa -D_REENTRANT
LDFLAGS: -lm -lpthread -lssl -lcrypto -lao -lasound -lavahi-common -lavahi-client
Configure successful. You may now build with 'make'
#開始建置
pi@ShiunPiSnd ~/shairport $ make
#安裝到/usr/local/bin
pi@ShiunPiSnd ~/shairport $ sudo make install
3. 測試ShairPort
將Pi模擬成AirPlay裝置,並設定名稱為AirPi
pi@ShiunPiSnd ~/shairport $ shairport -a "AirPi"
i. Mac使用ShairPort
壓著鍵盤上的option鍵對喇叭圖示點一下,選擇音源輸出為AirPi
隨便播放音樂試試看~
ii. iPhone場合
從畫面下方向上滑叫出控制中心,點選AirPlay後選擇AirPi
4. 設定為開機啟動
# 複製設定檔到相對應的位置
pi@ShiunPiSnd ~/shairport $ sudo cp -r scripts/debian/* /etc/
# 設定使用者為pi
pi@ShiunPiSnd ~/shairport $ sudo vi /etc/default/shairport
# User and group under whihc shairport should be run
# user should have permission to output sound
# Check the audio output documentation for details.
#USER=shairport
USER=pi
#GROUP=nogroup
# 修正使用sudo service shairport發生錯誤問題
pi@ShiunPiSnd ~/shairport $ sudo vi /etc/init.d/shairport
# User and group under whihc shairport should be run
PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="Shairport Airtunes emulator"
NAME=shairport
#DAEMON=/usr/bin/shairport
DAEMON=/usr/local/bin/shairport # 預設shairport安裝路徑應在/usr/local/bin下
# 設定shairport為開機啟動
pi@ShiunPiSnd ~/shairport $ sudo update-rc.d shairport defaults
重新啟動Pi以後就可以抓到AirPlay裝置啦~
注意:由daemon啟動的ShairPort預設裝置名稱為Pi的host name
參考資料
1. GitHub: abrasive/shairport2. 使用Shairport 讓你的Raspberry Pi 變成AirPlay 音樂播放器
沒有留言:
張貼留言