为了能让我的pi0w可以连接蓝牙音箱,在网上逛了两天,看了很多资料多数都不好用,很多是因为作者太不负责任,写的东西,很多都写的不清楚,导致不成功。这个方法是我参考了别人的方法,经过自己实践总结出来的。首先感谢原作者,原文件链接:https://bbs.hassbian.com/thread-3404-1-1.html话不多说,直接上成功的方法:
一、安装软件。
apt-get install pulseaudio pulseaudio-module-bluetooth bluez bluez-firmware
二、添加用户:
adduser root pulse-access
adduser pi pulse-access
三、修改文件:
- vim /etc/dbus-1/system.d/bluetooth.conf
在</busconfig>之前添加如下内容,注意不是修改内容,这步很关键。
<policy user="pulse">
<allow send_destination="org.bluez"/>
</policy>
- vim /etc/pulse/system.pa在文件的最后添加,不是修改原内容。
### Bluetooth Support
.ifexists module-bluetooth-discover.so
load-module module-bluetooth-discover
load-module module-bluetooth-policy
.endif
- vim /etc/pulse/default.pa 在原文load-module module-native-protocol-tcp后面添加auth-anonymous=1。
load-module module-native-protocol-tcp auth-anonymous=1
- vim /etc/pulse/daemon.conf(这个文件修不修改都好像没什么影响。)
resample-method = speex-fixed-3
- vim /etc/systemd/system/pulseaudio.service(这个文件原来没有,要新建。添加如下内容。
[Unit]
Description=Pulse Audio
[Service]
Type=simple
ExecStart=/usr/bin/pulseaudio --system --disallow-exit --disable-shm --exit-idle-time=-1
[Install]
WantedBy=multi-user.target
四、开启服务:
systemctl daemon-reload (重启加载进程)
systemctl restart Bluetooth (重启bluetooth进程)
systemctl start pulseaudio.service 启动pulseaudio进程)
systemctl enable pulseaudio.service (pulseaudio进程开机自启动)
systemctl status Bluetooth (查看bluetooth进程状态)
五、连接蓝牙音箱:
#bluetoothctl
[bluetooth]#power on
[bluetooth]#agent on
[bluetooth]#default-agent
[bluetooth]#scan on (扫描附近蓝牙设备)
[bluetooth]#pair xx:xx:xx:xx:xx:xx (配对(后面是蓝牙地址))
[bluetooth]#trust xx:xx:xx:xx:xx:xx (信任蓝牙设备)
[bluetooth]#connect xx:xx:xx:xx:xx:xx (连接蓝牙设备)
[bluetooth]#scan off (关闭扫描)
[bluetooth]#exit
有的设备在这步的时候连接上后马上会断,不影响,exit蓝牙后,关闭蓝牙音箱再打开就会自动连接,正常使用了。
六、播放音乐
mplayer file.mp3