簡體   English   中英

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

僅返回一些屬性:

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

返回值:

<!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>

該方法可以正常工作,但我希望也可以訪問諸如shuffle設置和track字典對象之類的東西。 主機(Raspberry Pi Zero W)已連接到我的Android手機,該手機正在從那里播放音樂。

Bluez僅在DBus屬性中顯示目標支持的應用程序設置。 換句話說,您在DBus內省中看到的屬性是可能的設置,而GetAll方法返回的屬性是目標設備的支持設置。 建立AVRCP藍牙配置文件的控制器角色的Bluez在建立連接后向目標設備發送“列表播放器應用程序設置(11)”命令; 對該命令的響應將告知目標支持的所有應用程序設置。 因此,控制器(即您的Raspberry Pi)只能在目標上更改這些設置。 請參閱bluez源中profile / avtcp.c中的代碼以獲取更好的理解。

要進行驗證,您可以連接任何其他已知的AVRCP配置文件支持的耳機,該耳機可以更改“重復”之類的設置,並查看其是否適用於您的手機。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM