BlueZ (5.43) 读取 MediaPlayer1 属性 (Python)
BlueZ (5.43) read MediaPlayer1 properties (Python)
我似乎无法使用 Python:
访问 BlueZ MediaPlayer1 接口的某些(大部分)属性
#!/usr/bin/python
import dbus
bus = dbus.SystemBus()
player = bus.get_object('org.bluez','/org/bluez/hci0/dev_78_6A_89_FA_1C_95/player0')
BT_Media_iface = dbus.Interface(player, dbus_interface='org.bluez.MediaPlayer1')
BT_Media_props = dbus.Interface(player, "org.freedesktop.DBus.Properties")
props = BT_Media_props.GetAll("org.bluez.MediaPlayer1")
print props
Returns只有几个属性:
dbus.Dictionary({dbus.String(u'Device'): dbus.ObjectPath('/org/bluez/hci0/dev_78_6A_89_FA_1C_95', variant_level=1), dbus.String(u'Position'): dbus.UInt32(0L, variant_level=1)}, signature=dbus.Signature('sv'))
根据 API (https://kernel.googlesource.com/pub/scm/bluetooth/bluez/+/5.43/doc/media-api.txt) 和 Introspective,我应该有更多可用的属性。
查询内省:
dbus-send --system --type=method_call --print-reply --dest=org.bluez /org/bluez/hci0/dev_78_6A_89_FA_1C_95/player0 org.freedesktop.DBus.Introspectable.Introspect
Returns:
<!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" type="s" direction="out"/></method>
</interface>
<interface name="org.bluez.MediaPlayer1">
<method name="Play"></method>
<method name="Pause"></method>
<method name="Stop"></method>
<method name="Next"></method>
<method name="Previous"></method>
<method name="FastForward"></method>
<method name="Rewind"></method>
<property name="Name" type="s" access="read"></property>
<property name="Type" type="s" access="read"></property>
<property name="Subtype" type="s" access="read"></property>
<property name="Position" type="u" access="read"></property>
<property name="Status" type="s" access="read"></property>
<property name="Equalizer" type="s" access="readwrite"></property>
<property name="Repeat" type="s" access="readwrite"></property>
<property name="Shuffle" type="s" access="readwrite"></property>
<property name="Scan" type="s" access="readwrite"></property>
<property name="Track" type="a{sv}" access="read"></property>
<property name="Device" type="o" access="read"></property>
<property name="Browsable" type="b" access="read"></property>
<property name="Searchable" type="b" access="read"></property>
<property name="Playlist" type="o" access="read"></property>
</interface>
<interface name="org.freedesktop.DBus.Properties">
<method name="Get"><arg name="interface" type="s" direction="in"/><arg name="name" type="s" direction="in"/><arg name="value" type="v" direction="out"/></method>
<method name="Set"><arg name="interface" type="s" direction="in"/><arg name="name" type="s" direction="in"/><arg name="value" type="v" direction="in"/></method>
<method name="GetAll"><arg name="interface" type="s" direction="in"/><arg name="properties" type="a{sv}" direction="out"/></method>
<signal name="PropertiesChanged"><arg name="interface" type="s"/><arg name="changed_properties" type="a{sv}"/><arg name="invalidated_properties" type="as"/></signal>
</interface>
</node>
这些方法工作正常,但我希望还可以访问随机播放设置和跟踪字典对象等内容。主机 (Raspberry Pi 零 W) 连接到我的 Android phone,它正在从那里播放音乐。
Bluez 仅在 DBus 属性中显示目标支持的应用程序设置。换句话说,您在 DBus 自省上看到的属性是可能的设置,GetAll 方法 returns 的属性是目标设备支持的设置。扮演AVRCP蓝牙配置文件控制器角色的Bluez在连接建立后向目标设备发送"List Player Application Settings (11)"命令;对该命令的响应告知目标支持的所有应用程序设置。因此,控制器(即 Raspberry Pi 在您的情况下)只能更改目标上的这些设置。请参阅 bluez 源代码 profile/avtcp.c 中的代码以获得更好的理解。
要验证,您可以连接任何其他已知的支持 AVRCP 配置文件的耳机,它可以选择更改 "repeat" 等设置,并查看它是否适用于您的 phone。
我似乎无法使用 Python:
访问 BlueZ MediaPlayer1 接口的某些(大部分)属性#!/usr/bin/python
import dbus
bus = dbus.SystemBus()
player = bus.get_object('org.bluez','/org/bluez/hci0/dev_78_6A_89_FA_1C_95/player0')
BT_Media_iface = dbus.Interface(player, dbus_interface='org.bluez.MediaPlayer1')
BT_Media_props = dbus.Interface(player, "org.freedesktop.DBus.Properties")
props = BT_Media_props.GetAll("org.bluez.MediaPlayer1")
print props
Returns只有几个属性:
dbus.Dictionary({dbus.String(u'Device'): dbus.ObjectPath('/org/bluez/hci0/dev_78_6A_89_FA_1C_95', variant_level=1), dbus.String(u'Position'): dbus.UInt32(0L, variant_level=1)}, signature=dbus.Signature('sv'))
根据 API (https://kernel.googlesource.com/pub/scm/bluetooth/bluez/+/5.43/doc/media-api.txt) 和 Introspective,我应该有更多可用的属性。
查询内省:
dbus-send --system --type=method_call --print-reply --dest=org.bluez /org/bluez/hci0/dev_78_6A_89_FA_1C_95/player0 org.freedesktop.DBus.Introspectable.Introspect
Returns:
<!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" type="s" direction="out"/></method>
</interface>
<interface name="org.bluez.MediaPlayer1">
<method name="Play"></method>
<method name="Pause"></method>
<method name="Stop"></method>
<method name="Next"></method>
<method name="Previous"></method>
<method name="FastForward"></method>
<method name="Rewind"></method>
<property name="Name" type="s" access="read"></property>
<property name="Type" type="s" access="read"></property>
<property name="Subtype" type="s" access="read"></property>
<property name="Position" type="u" access="read"></property>
<property name="Status" type="s" access="read"></property>
<property name="Equalizer" type="s" access="readwrite"></property>
<property name="Repeat" type="s" access="readwrite"></property>
<property name="Shuffle" type="s" access="readwrite"></property>
<property name="Scan" type="s" access="readwrite"></property>
<property name="Track" type="a{sv}" access="read"></property>
<property name="Device" type="o" access="read"></property>
<property name="Browsable" type="b" access="read"></property>
<property name="Searchable" type="b" access="read"></property>
<property name="Playlist" type="o" access="read"></property>
</interface>
<interface name="org.freedesktop.DBus.Properties">
<method name="Get"><arg name="interface" type="s" direction="in"/><arg name="name" type="s" direction="in"/><arg name="value" type="v" direction="out"/></method>
<method name="Set"><arg name="interface" type="s" direction="in"/><arg name="name" type="s" direction="in"/><arg name="value" type="v" direction="in"/></method>
<method name="GetAll"><arg name="interface" type="s" direction="in"/><arg name="properties" type="a{sv}" direction="out"/></method>
<signal name="PropertiesChanged"><arg name="interface" type="s"/><arg name="changed_properties" type="a{sv}"/><arg name="invalidated_properties" type="as"/></signal>
</interface>
</node>
这些方法工作正常,但我希望还可以访问随机播放设置和跟踪字典对象等内容。主机 (Raspberry Pi 零 W) 连接到我的 Android phone,它正在从那里播放音乐。
Bluez 仅在 DBus 属性中显示目标支持的应用程序设置。换句话说,您在 DBus 自省上看到的属性是可能的设置,GetAll 方法 returns 的属性是目标设备支持的设置。扮演AVRCP蓝牙配置文件控制器角色的Bluez在连接建立后向目标设备发送"List Player Application Settings (11)"命令;对该命令的响应告知目标支持的所有应用程序设置。因此,控制器(即 Raspberry Pi 在您的情况下)只能更改目标上的这些设置。请参阅 bluez 源代码 profile/avtcp.c 中的代码以获得更好的理解。
要验证,您可以连接任何其他已知的支持 AVRCP 配置文件的耳机,它可以选择更改 "repeat" 等设置,并查看它是否适用于您的 phone。