2020年11月20日 星期五

[解決問題]PiCorePlayer - USB Audio 斷線自動重連程序

因為PiCorePlayer通常都掛載24小時運行的Raspberry Pi上面,因此不可能把擴大機跟PI一起關閉,其開關機的速度也不一樣,如果擴大機已經關了,USB Audio就會斷線,再把擴大機打開,Squeezelite只要沒抓到Sound也不會自動重連,一定要到PiCorePlayer介面Restart服務才能繼續聽音樂,恩!真的很麻煩!

Most of PiCorePlayer is runs 24 hours a day, so it cannot be turned on/off at the same time as the amplifier/dac. When the amplifier/dac is turned off, the USB Audio will be disconnected, but when the amplifier/dac is turned on again, Squeezelite will not automatically reconnect the USB Audio. You must restart the service on the PiCorePlayer interface to continue the connection. Really troublesome.

另外,如果你選擇用USB Audio當輸出的話,Squeezelite只要沒抓到Sound Card就也會啟動失敗,因此,本篇文章教學就要把這個過程自動化。我提供個簡單的小程序,讓這個兩個機制變成全自動偵測!

If you choose to use USB Audio as the output, Squeezelite will fail to start as long as it does not catch the Sound Card. Therefore, I provide a small script to make these two mechanisms into automatic detection.


登入ssh開始操作,[ssh port: 22, username: tc, password: piCore]

tc@piCorePlayer:~$ sudo su
root@piCorePlayer:/home/tc#
root@piCorePlayer:/home/tc# vi /opt/check_usb_audio.sh

新增檔案,>>vi編輯器,不懂得請按此學習<<

Create file with VI editor.

SQE_FLAG=false
while true
do
	aplay -l | grep 'USB Audio' &> /dev/null
	if [ $? == 0 ]; then
		if [ $SQE_FLAG == false ]; then
			sudo /usr/local/etc/init.d/squeezelite restart
			SQE_FLAG=true
		fi
		sleep 1
	else
		SQE_FLAG=false
		sleep 1
	fi
done

root@piCorePlayer:/home/tc# sed -i 's/\r$//' /opt/check_usb_audio.sh
root@piCorePlayer:/home/tc# chmod -c 777 /opt/check_usb_audio.sh
root@piCorePlayer:/home/tc# vi /opt/bootlocal.sh

插入一行,>>vi編輯器,不懂得請按此學習<<

Insert a line in the program with the VI editor.

/opt/check_usb_audio.sh &

root@piCorePlayer:/home/tc# pcp bu
root@piCorePlayer:/home/tc# reboot

完成,你的PiCorePlayer將自動連接USB Audio!

Done, your PiCorePlayer will automatically connect to USB Audio.



延伸閱讀
[開箱]LEAK Stereo 130 & Wharfedale EVO 4.2我的第一組兩聲道
[開箱]Raspberry Pi4B Volumio 網路數位串流播放器
[開箱]蝦皮買的便宜音響腳釘,到底有沒有效果呢?
[開箱]Volumio+Tidal完美體驗,無損音質體驗真的很棒,整合的不錯!
[開箱]終於搞定PiCorePlayer,聽到聲音好感動!(內有很多楣角)

沒有留言:

張貼留言