设备支持bluez5.62+PulseAudio
A2DP 连接命令 bluetoothctl
[bluetoothctl]
power on/off #蓝牙上电/下电
agent NoInputNoOutput # 使用这种模式作为蓝牙sink可以无需介入直接连接
system-alias 'QT-LINX1' #设置蓝牙别名
discoverable on/off #蓝牙可发现 开启/关闭
info #显示连接设备的信息
pairable on/off #蓝牙可配对 开启/关闭
connect #连接设备
disconnect #段连设备
bluetoothctl agent NoInputNoOutput 执行后, 一路输入yes:
[agent] Confirm passkey 193261 (yes/no): yes
Authorize service
[agent] Authorize service 00001108-0000-1000-8000-00805f9b34fb (yes/no): yes
Authorize service
[agent] Authorize service 0000110d-0000-1000-8000-00805f9b34fb (yes/no): yes
AVRCP(音频/视频遥控协议,Audio/Video-Remote-Control-Profile)
pactl list cards #列出声卡
Card #0
Name: alsa_card.platform-rk809-sound
Driver: module-alsa-card.c
Owner Module: 6
Properties:
alsa.card = "0"
alsa.card_name = "rockchip-rk809"
alsa.long_card_name = "rockchip-rk809"
device.bus_path = "platform-rk809-sound"
sysfs.path = "/devices/platform/rk809-sound/sound/card0"
device.string = "0"
device.description = "rockchip-rk809"
module-udev-detect.discovered = "1"
device.icon_name = "audio-card"
Profiles:
HiFi: Default (sinks: 1, sources: 1, priority: 8000, available: yes)
off: Off (sinks: 0, sources: 0, priority: 0, available: yes)
Active Profile: HiFi
Ports:
[Out] Headphones: Headphones (type: Headphones, priority: 200, latency offset: 0 usec, availability unknown)
Part of profile(s): HiFi
[Out] Speaker: Speaker (type: Speaker, priority: 100, latency offset: 0 usec, availability unknown)
Part of profile(s): HiFi
[In] Headset: Headset Microphone (type: Headset, priority: 200, latency offset: 0 usec, availability unknown)
Part of profile(s): HiFi
[In] Mic: Internal Microphone (type: Mic, priority: 100, latency offset: 0 usec, availability unknown)
Part of profile(s): HiFi
Card #8
Name: bluez_card.04_D3_B5_B2_7E_40
Driver: module-bluez5-device.c
Owner Module: 36
Properties:
device.description = "linx1"
device.string = "04:D3:B5:B2:7E:40"
device.api = "bluez"
device.class = "sound"
device.bus = "bluetooth"
device.form_factor = "phone"
bluez.path = "/org/bluez/hci0/dev_04_D3_B5_B2_7E_40"
bluez.class = "0x5a020c"
bluez.alias = "linx1"
device.icon_name = "audio-card-bluetooth"
Profiles:
headset_audio_gateway: Headset Audio Gateway (HSP/HFP) (sinks: 1, sources: 1, priority: 10, available: yes)
a2dp_source: High Fidelity Capture (A2DP Source) (sinks: 0, sources: 1, priority: 20, available: yes)
off: Off (sinks: 0, sources: 0, priority: 0, available: yes)
Active Profile: a2dp_source
Ports:
phone-output: Phone (type: Phone, priority: 0, latency offset: 0 usec, availability unknown)
Part of profile(s): headset_audio_gateway
phone-input: Phone (type: Phone, priority: 0, latency offset: 0 usec, available)
Part of profile(s): headset_audio_gateway, a2dp_source
bluez.path = “/org/bluez/hci0/dev_04_D3_B5_B2_7E_40” 利用这个信息可以进行方法内省:
dbus-send --system --print-reply --dest=org.bluez /org/bluez/hci0/dev_04_D3_B5_B2_7E_40 org.freedesktop.DBus.Introspectable.Introspect
设备输出:
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN""http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd"><node>
<interface name="org.freedesktop.DBus.Introspectable">
<method name="Introspect">
<arg name="xml" direction="out" type="s" />
</method>
</interface>
<interface name="org.bluez.Device1">
<method name="Disconnect"></method>
<method name="Connect"></method>
<method name="ConnectProfile">
<arg name="UUID" direction="in" type="s" />
</method>
<method name="DisconnectProfile">
<arg name="UUID" direction="in" type="s" />
</method>
<method name="Pair"></method>
<method name="CancelPairing"></method>
<property name="Address" access="read" type="s"></property>
<property name="AddressType" access="read" type="s"></property>
<property name="Name" access="read" type="s"></property>
<property name="Alias" access="readwrite" type="s"></property>
<property name="Class" access="read" type="u"></property>
<property name="Appearance" access="read" type="q"></property>
<property name="Icon" access="read" type="s"></property>
<property name="Paired" access="read" type="b"></property>
<property name="Trusted" access="readwrite" type="b"></property>
<property name="Blocked" access="readwrite" type="b"></property>
<property name="LegacyPairing" access="read" type="b"></property>
<property name="RSSI" access="read" type="n"></property>
<property name="Connected" access="read" type="b"></property>
<property name="UUIDs" access="read" type="as"></property>
<property name="Modalias" access="read" type="s"></property>
<property name="Adapter" access="read" type="o"></property>
<property name="ManufacturerData" access="read" type="a{qv}"></property>
<property name="ServiceData" access="read" type="a{sv}"></property>
<property name="TxPower" access="read" type="n"></property>
<property name="ServicesResolved" access="read" type="b"></property>
<property name="WakeAllowed" access="readwrite" type="b"></property>
</interface>
<interface name="org.freedesktop.DBus.Properties">
<method name="Get">
<arg name="interface" direction="in" type="s" />
<arg name="name" direction="in" type="s" />
<arg name="value" direction="out" type="v" />
</method>
<method name="Set">
<arg name="interface" direction="in" type="s" />
<arg name="name" direction="in" type="s" />
<arg name="value" direction="in" type="v" />
</method>
<method name="GetAll">
<arg name="interface" direction="in" type="s" />
<arg name="properties" direction="out" type="a{sv}" />
</method>
<signal name="PropertiesChanged">
<arg name="interface" type="s" />
<arg name="changed_properties" type="a{sv}" />
<arg name="invalidated_properties" type="as" />
</signal>
</interface>
<interface name="org.bluez.MediaControl1">
<method name="Play">
<annotation name="org.freedesktop.DBus.Deprecated" value="true" />
</method>
<method name="Pause">
<annotation name="org.freedesktop.DBus.Deprecated" value="true" />
</method>
<method name="Stop">
<annotation name="org.freedesktop.DBus.Deprecated" value="true" />
</method>
<method name="Next">
<annotation name="org.freedesktop.DBus.Deprecated" value="true" />
</method>
<method name="Previous">
<annotation name="org.freedesktop.DBus.Deprecated" value="true" />
</method>
<method name="VolumeUp">
<annotation name="org.freedesktop.DBus.Deprecated" value="true" />
</method>
<method name="VolumeDown">
<annotation name="org.freedesktop.DBus.Deprecated" value="true" />
</method>
<method name="FastForward">
<annotation name="org.freedesktop.DBus.Deprecated" value="true" />
</method>
<method name="Rewind">
<annotation name="org.freedesktop.DBus.Deprecated" value="true" />
</method>
<property name="Connected" access="read" type="b"></property>
<property name="Player" access="read" type="o"></property>
</interface>
<node name="fd2" />
<node name="player0" />
<node name="sep1" />
<node name="sep2" />
<node name="sep3" />
<node name="sep4" />
</node>
得出如下控制音频的命令:
dbus-send --system --print-reply --dest=org.bluez /org/bluez/hci0/dev_04_D3_B5_B2_7E_40 org.bluez.MediaControl1.Play
dbus-send --system --print-reply --dest=org.bluez /org/bluez/hci0/dev_04_D3_B5_B2_7E_40 org.bluez.MediaControl1.Stop
dbus-send --system --print-reply --dest=org.bluez /org/bluez/hci0/dev_04_D3_B5_B2_7E_40 org.bluez.MediaControl1.Next
dbus-send --system --print-reply --dest=org.bluez /org/bluez/hci0/dev_04_D3_B5_B2_7E_40 org.bluez.MediaControl1.Previous
参考
https://blog.csdn.net/huohongpeng/article/details/115786953
http://www.360doc.com/content/22/0920/13/20880499_1048648984.shtml
https://whycan.com/p_80548.html