安装依赖包
sudo apt-get update
sudo apt-get install pulseaudio pulseaudio-module-bluetooth
sudo apt-get install pi-bluetooth bluez bluez-firmware blueman
sudo apt install bluez bluez-firmware pulseaudio pulseaudio-module-bluetooth
sudo /etc/init.d/bluetooth restart
设置蓝牙配对连接音箱
bluetoothctl
show
power on
default-agent
scan on
pair 41:42:90:F3:9E:B5
trust 41:42:90:F3:9E:B5
connect 41:42:90:F3:9E:B5
info 41:42:90:F3:9E:B5
exit
树莓派每次开机后都要执行此脚本来连接蓝牙音箱
/home/pi/myboot/startboot.sh
#!/bin/bash
sleep 1
pulseaudio --k
pulseaudio --start
bluetoothctl power on
bluetoothctl connect 41:42:90:F3:9E:B5
sleep 5
aplay /home/pi/myboot/startaudio.wav
echo 'audio OK~~~'
*下面这个蓝牙开机自连脚本其实是有问题的,开机自启后看似蓝牙音箱是已连接状态了,但是播放音乐还是无声,还需要在当前SSH连接终端手动执行一次上面startboot.sh
脚本才行。
开机启动用
/etc/init.d/startboot
#!/bin/sh
#/etc/i