Pi Zero W สลับแหล่งเสียงไปยังลำโพง Bluetooth
เพื่อดูว่ามีแหล่งเสียงอะไรอยู่บ้าง pi@raspberrypi:~ $ pactl list short sinks
0 alsa_output.pivumeter module-alsa-sink.c s16le 2ch 44100Hz RUNNING
3 bluez_sink.F8_DF_15_04_14_43.a2dp_sink module-bluez5-device.c s16le 2ch 44100Hz IDLE
สลับไปลำโพง (3) เพราะเปิด/ปิด 3 ครั้งมันเลยเป็นเบอร์ 3 pi@raspberrypi:~ $ pactl move-sink-input 0 3
สรุปออกมาเป็น Code ดังนี้ pactl move-sink-input 0 $(pactl list short sinks | grep bluez | cut -f 1)
ทีนี้ก็สั่งให้มันเปลี่ยนเอง pi@hifi:~ $ cat auto.sh
#!/bin/sh
while :
do
tail -fn0 /var/log/syslog | egrep -m 1 "bluez"
echo "Found BT"
sleep 1
pactl move-sink-input 0 $(pactl list short sinks | grep bluez | cut -f 1)
done
chmod +x auto.sh crontab -e เพิ่มนี่เข้าไป @reboot /home/pi/auto.sh >/dev/null 2>&1
Create Date : 29 กรกฎาคม 2564 |
| |
|
Last Update : 30 กรกฎาคม 2564 14:24:47 น. |
| |
Counter : 467 Pageviews. |
| |
|
|