您当前的位置:首页 > 计算机 > 系统应用 > Linux

在 archlinux 中使用蓝牙耳机

时间:12-14来源:作者:点击数:

安装必要的软件包

pacman -S bluez bluez-utils bluez-firmware pulseaudio-bluetooth pavucontrol pulseaudio-alsa

其中:

  • bluez 软件包提供蓝牙协议栈
  • bluez-utils 软件包提供 bluetoothctl 工具
  • pulseaudio-bluetooth 则为 bluez 提供了 PulseAudio 音频服务,若没有安装则蓝牙设备在配对完成后,连接会失败,提示
  • pavucontrol 则提供了 pulseaudio 的图形化控制界面
  • pulseaudio-alsa(可选)则使 pulseaudio 和 alsa 协同使用,之后就可以用 alsamixer 来管理蓝牙音频了

启动蓝牙服务

systemctl enable bluetooth
systemctl start bluetooth

启动 pulseaudio 服务

pulseaudio -k                   # 确保没有pulseaudio启动
pulseaudio --start              # 启动pulseaudio服务

将用户加入 lp 用户组

安装 bluz 后就应该会自动创建 lp 用户组了,因此无需自己再创建新组

usermod -a -G lp $USER

默认情况下,蓝牙仅为 lp 用户组中的用户启用 bnep0 设备。如果想要加入蓝牙系统,需确认已将用户加入该组。可以修改 /etc/dbus-1/system.d/bluetooth.conf 文件中相应的组配置来实现。

配置蓝牙

启动 bluetoothctl 交互命令.可以输入 help 列出所有有效的命令。

  • 输入 power on 命令打开控制器电源。默认是关闭的。
  • 输入 devices 命令获取要配对设备的 MAC 地址。
  • 如果设备未在清单中列出,输入 scan on 命令设置设备发现模式。
  • 输入 agent on 命令打开代理。
  • 输入 pair $MAC 开始配对(支持 tab 键补全)。
  • 如果使用无 PIN 码设备,再次连接可能需要手工认证。输入 trust $MAC 命令。
  • 用 connect $MAC 命令建立连接。

以下为一个交互实例:

# bluetoothctl 
[NEW] Controller 00:10:20:30:40:50 pi [default]
[bluetooth]# agent KeyboardOnly 
Agent registered
[bluetooth]# default-agent 
Default agent request successful
[bluetooth]# scan on
Discovery started
[CHG] Controller 00:10:20:30:40:50 Discovering: yes
[NEW] Device 00:12:34:56:78:90 myLino
[CHG] Device 00:12:34:56:78:90 LegacyPairing: yes
[bluetooth]# pair 00:12:34:56:78:90
Attempting to pair with 00:12:34:56:78:90
[CHG] Device 00:12:34:56:78:90 Connected: yes
[CHG] Device 00:12:34:56:78:90 Connected: no
[CHG] Device 00:12:34:56:78:90 Connected: yes
Request PIN code
[agent] Enter PIN code: 1234
[CHG] Device 00:12:34:56:78:90 Paired: yes
Pairing successful
[CHG] Device 00:12:34:56:78:90 Connected: no
[bluetooth]# connect 00:12:34:56:78:90
Attempting to connect to 00:12:34:56:78:90
[CHG] Device 00:12:34:56:78:90 Connected: yes
Connection successful

设置自动启动蓝牙

将 /etc/bluetooth/main.conf 最后的 AutoEnable 值修改为 true

ansible localhost -m lineinfile -a "path=/etc/bluetooth/main.conf line='AutoEnable=true'"

指定使用蓝牙音频输出

通过 pavucontrol 的 Playback 和 Pecording 标签页重定向音频的输入和输出

方便获取更多学习、工作、生活信息请关注本站微信公众号城东书院 微信服务号城东书院 微信订阅号
推荐内容
相关内容
栏目更新
栏目热门
本栏推荐