Raspberry Pi + Bluez + A2DP + AVRCP
Raspberry Pi + Bluez + A2DP + AVRCP
在过去的 2 天里,我一直在谷歌上搜索一种方法来通过我的 Raspiberry pi 无头扬声器从我的 iPhone 控制媒体播放。
我已经使用以下教程成功设置了 pi:
Headless A2DP Audio Streaming on Raspbian Stretch
现在我正在寻找一种方法来控制来自 raspberry pi.
的音频流的播放
我一直在研究 MediaTransport1、MediaPlayer1、MediaControl1,但不幸的是我没有成功。
举几个我试错过的例子:
用于:
dbus-send --system --print-reply --dest=org.bluez /org/bluez/hci0/dev_C8_85_50_B1_C8_6B org.bluez.MediaPlayer1.Pause
我收到了:
Error org.freedesktop.DBus.Error.UnknownMethod: Method "Pause" with signature "" on interface "org.bluez.MediaPlayer1" doesn't exist
对于
qdbus --system org.bluez /org/bluez/hci0/dev_C8_85_50_B1_C8_6B/fd0 org.freedesktop.DBus.Properties.Set org.bluez.MediaTransport1 Volume 127
我收到了
Error: org.freedesktop.DBus.Error.InvalidSignature
Invalid signature for 'Volume'
此外,我发现了一个播放器,我认为我可以用它来构建自己的脚本作为示例Here,但我遇到了一个错误:
pi@raspberrypi:~/blueutils $ python simpleplayer.py
Available commands:
PropertiesChanged(interface, properties)
help(cmd)
Use python syntax to pass arguments to available methods.
E.g.: PropertiesChanged({'Metadata' : {'Title': 'My title', 'Album': 'my album' }})
>>> <Interface <ProxyObject wrapping <dbus._dbus.SystemBus (system) at 0xb61968d0> :1.13 /org/bluez/hci0 at 0xb619db70> implementing 'org.bluez.Media1' at 0xb619dc50>
Traceback (most recent call last):
File "simpleplayer.py", line 197, in <module>
media.RegisterPlayer(dbus.ObjectPath(path), player.properties)
File "/usr/lib/python2.7/dist-packages/dbus/proxies.py", line 70, in __call__
return self._proxy_method(*args, **keywords)
File "/usr/lib/python2.7/dist-packages/dbus/proxies.py", line 145, in __call__
**keywords)
File "/usr/lib/python2.7/dist-packages/dbus/connection.py", line 651, in call_blocking
message, timeout)
dbus.exceptions.DBusException: org.bluez.Error.NotSupported: Operation is not supported
当我反省时
dbus-send --system --print-reply --dest=org.bluez /org/bluez/hci0 org.freedesktop.DBus.Introspectable.Introspect
我得到他的:
<node>
<interface name="org.freedesktop.DBus.Introspectable">
<method name="Introspect">
<arg name="xml" type="s" direction="out"/>
</method>
</interface>
<interface name="org.bluez.Adapter1">
<method name="StartDiscovery"></method>
<method name="SetDiscoveryFilter">
<arg name="properties" type="a{sv}" direction="in"/>
</method>
<method name="StopDiscovery"></method>
<method name="RemoveDevice">
<arg name="device" type="o" direction="in"/>
</method>
<property name="Address" type="s" access="read"></property>
<property name="Name" type="s" access="read"></property>
<property name="Alias" type="s" access="readwrite"></property>
<property name="Class" type="u" access="read"></property>
<property name="Powered" type="b" access="readwrite"></property>
<property name="Discoverable" type="b" access="readwrite"></property>
<property name="DiscoverableTimeout" type="u" access="readwrite"></property>]
<property name="Pairable" type="b" access="readwrite"></property>
<property name="PairableTimeout" type="u" access="readwrite"></property>
<property name="Discovering" type="b" access="read"></property>
<property name="UUIDs" type="as" access="read"></property>
<property name="Modalias" type="s" 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>
<interface name="org.bluez.GattManager1">
<method name="RegisterApplication">
<arg name="application" type="o" direction="in"/>
<arg name="options" type="a{sv}" direction="in"/>
</method>
<method name="UnregisterApplication">
<arg name="application" type="o" direction="in"/>
</method>
</interface>
<interface name="org.bluez.Media1">
<method name="RegisterEndpoint">
<arg name="endpoint" type="o" direction="in"/>
<arg name="properties" type="a{sv}" direction="in"/>
</method>
<method name="UnregisterEndpoint">
<arg name="endpoint" type="o" direction="in"/>
</method>
<method name="RegisterPlayer">
<arg name="player" type="o" direction="in"/>
<arg name="properties" type="a{sv}" direction="in"/>
</method>
<method name="UnregisterPlayer">
<arg name="player" type="o" direction="in"/>
</method>
</interface>
<node name="dev_40_9C_28_07_63_DD"/>
<node name="dev_C8_85_50_B1_C8_6B"/>
</node>
谁能帮我解决这个问题,或者谁知道使用 raspberry pi 在 phone 上控制音乐播放的程序?
此致。
更新 1:
非常感谢@Parthiban,因为它工作得很好。
此外,我不得不说我按照这里的教程将 bluez 版本重新安装到 5.50:Install bluez on the Raspberry Pi 因为我看不到 /playerX(在我的例子中是 0)。在我编译源代码之前,我做了一些额外的事情(不确定它是否相关但没有坏处),我添加了 .auto_connect = true
指示的 avrcp 配置文件:
希望这对可能遇到我的问题的每个人都有帮助
您需要指定签名来设置音量,如下所示,
dbus-send --system --print-reply --type=method_call --dest='org.bluez' '/org/bluez/hci0/dev_C8_85_50_B1_C8_6B/fd0' org.freedesktop.DBus.Properties.Set string:"org.bluez.MediaTransport1" string:"Volume" variant:uint16:127
这是因为dbus specification中提到使用set时需要指定三个参数,
- 接口名称
- 属性 姓名
- 属性 变体值
对于暂停方法,请使用“org.freedesktop.DBus.Introspectable.Introspect
”浏览设备的“org.bluez.MediaPlayer1
”界面。您用来访问方法 "Pause" 的对象路径是错误的。如here所述,您需要使用“[variable prefix]/{hci0,hci1,...}/dev_XX_XX_XX_XX_XX_XX/playerX
”。
所以在你的情况下,应该是,
dbus-send --system --print-reply --type=method_call --dest='org.bluez' '/org/bluez/hci0/dev_C8_85_50_B1_C8_6B/playerX' org.bluez.MediaPlayer1.Pause
其中 playerX 需要替换为您的设备播放器(您可以从 Introspect 获取它或在 "InterfaceAdded" Signal 上观看。
在过去的 2 天里,我一直在谷歌上搜索一种方法来通过我的 Raspiberry pi 无头扬声器从我的 iPhone 控制媒体播放。
我已经使用以下教程成功设置了 pi: Headless A2DP Audio Streaming on Raspbian Stretch 现在我正在寻找一种方法来控制来自 raspberry pi.
的音频流的播放我一直在研究 MediaTransport1、MediaPlayer1、MediaControl1,但不幸的是我没有成功。
举几个我试错过的例子:
用于:
dbus-send --system --print-reply --dest=org.bluez /org/bluez/hci0/dev_C8_85_50_B1_C8_6B org.bluez.MediaPlayer1.Pause
我收到了:
Error org.freedesktop.DBus.Error.UnknownMethod: Method "Pause" with signature "" on interface "org.bluez.MediaPlayer1" doesn't exist
对于
qdbus --system org.bluez /org/bluez/hci0/dev_C8_85_50_B1_C8_6B/fd0 org.freedesktop.DBus.Properties.Set org.bluez.MediaTransport1 Volume 127
我收到了
Error: org.freedesktop.DBus.Error.InvalidSignature
Invalid signature for 'Volume'
此外,我发现了一个播放器,我认为我可以用它来构建自己的脚本作为示例Here,但我遇到了一个错误:
pi@raspberrypi:~/blueutils $ python simpleplayer.py
Available commands:
PropertiesChanged(interface, properties)
help(cmd)
Use python syntax to pass arguments to available methods.
E.g.: PropertiesChanged({'Metadata' : {'Title': 'My title', 'Album': 'my album' }})
>>> <Interface <ProxyObject wrapping <dbus._dbus.SystemBus (system) at 0xb61968d0> :1.13 /org/bluez/hci0 at 0xb619db70> implementing 'org.bluez.Media1' at 0xb619dc50>
Traceback (most recent call last):
File "simpleplayer.py", line 197, in <module>
media.RegisterPlayer(dbus.ObjectPath(path), player.properties)
File "/usr/lib/python2.7/dist-packages/dbus/proxies.py", line 70, in __call__
return self._proxy_method(*args, **keywords)
File "/usr/lib/python2.7/dist-packages/dbus/proxies.py", line 145, in __call__
**keywords)
File "/usr/lib/python2.7/dist-packages/dbus/connection.py", line 651, in call_blocking
message, timeout)
dbus.exceptions.DBusException: org.bluez.Error.NotSupported: Operation is not supported
当我反省时
dbus-send --system --print-reply --dest=org.bluez /org/bluez/hci0 org.freedesktop.DBus.Introspectable.Introspect
我得到他的:
<node>
<interface name="org.freedesktop.DBus.Introspectable">
<method name="Introspect">
<arg name="xml" type="s" direction="out"/>
</method>
</interface>
<interface name="org.bluez.Adapter1">
<method name="StartDiscovery"></method>
<method name="SetDiscoveryFilter">
<arg name="properties" type="a{sv}" direction="in"/>
</method>
<method name="StopDiscovery"></method>
<method name="RemoveDevice">
<arg name="device" type="o" direction="in"/>
</method>
<property name="Address" type="s" access="read"></property>
<property name="Name" type="s" access="read"></property>
<property name="Alias" type="s" access="readwrite"></property>
<property name="Class" type="u" access="read"></property>
<property name="Powered" type="b" access="readwrite"></property>
<property name="Discoverable" type="b" access="readwrite"></property>
<property name="DiscoverableTimeout" type="u" access="readwrite"></property>]
<property name="Pairable" type="b" access="readwrite"></property>
<property name="PairableTimeout" type="u" access="readwrite"></property>
<property name="Discovering" type="b" access="read"></property>
<property name="UUIDs" type="as" access="read"></property>
<property name="Modalias" type="s" 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>
<interface name="org.bluez.GattManager1">
<method name="RegisterApplication">
<arg name="application" type="o" direction="in"/>
<arg name="options" type="a{sv}" direction="in"/>
</method>
<method name="UnregisterApplication">
<arg name="application" type="o" direction="in"/>
</method>
</interface>
<interface name="org.bluez.Media1">
<method name="RegisterEndpoint">
<arg name="endpoint" type="o" direction="in"/>
<arg name="properties" type="a{sv}" direction="in"/>
</method>
<method name="UnregisterEndpoint">
<arg name="endpoint" type="o" direction="in"/>
</method>
<method name="RegisterPlayer">
<arg name="player" type="o" direction="in"/>
<arg name="properties" type="a{sv}" direction="in"/>
</method>
<method name="UnregisterPlayer">
<arg name="player" type="o" direction="in"/>
</method>
</interface>
<node name="dev_40_9C_28_07_63_DD"/>
<node name="dev_C8_85_50_B1_C8_6B"/>
</node>
谁能帮我解决这个问题,或者谁知道使用 raspberry pi 在 phone 上控制音乐播放的程序?
此致。
更新 1: 非常感谢@Parthiban,因为它工作得很好。
此外,我不得不说我按照这里的教程将 bluez 版本重新安装到 5.50:Install bluez on the Raspberry Pi 因为我看不到 /playerX(在我的例子中是 0)。在我编译源代码之前,我做了一些额外的事情(不确定它是否相关但没有坏处),我添加了 .auto_connect = true
指示的 avrcp 配置文件:
希望这对可能遇到我的问题的每个人都有帮助
您需要指定签名来设置音量,如下所示,
dbus-send --system --print-reply --type=method_call --dest='org.bluez' '/org/bluez/hci0/dev_C8_85_50_B1_C8_6B/fd0' org.freedesktop.DBus.Properties.Set string:"org.bluez.MediaTransport1" string:"Volume" variant:uint16:127
这是因为dbus specification中提到使用set时需要指定三个参数,
- 接口名称
- 属性 姓名
- 属性 变体值
对于暂停方法,请使用“org.freedesktop.DBus.Introspectable.Introspect
”浏览设备的“org.bluez.MediaPlayer1
”界面。您用来访问方法 "Pause" 的对象路径是错误的。如here所述,您需要使用“[variable prefix]/{hci0,hci1,...}/dev_XX_XX_XX_XX_XX_XX/playerX
”。
所以在你的情况下,应该是,
dbus-send --system --print-reply --type=method_call --dest='org.bluez' '/org/bluez/hci0/dev_C8_85_50_B1_C8_6B/playerX' org.bluez.MediaPlayer1.Pause
其中 playerX 需要替换为您的设备播放器(您可以从 Introspect 获取它或在 "InterfaceAdded" Signal 上观看。