首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >树莓Pi + Bluez + A2DP + AVRCP

树莓Pi + Bluez + A2DP + AVRCP
EN

Stack Overflow用户
提问于 2018-09-06 22:39:49
回答 1查看 3.7K关注 0票数 2

在过去的两天里,我一直在谷歌上搜索一种方法,通过我的Raspiberry无头扬声器控制我的iPhone的媒体播放。

我已经使用以下教程成功地设置了pi:无头A2DP音频流在Raspbian拉伸中的应用,现在我正在寻找一种方法来控制来自raspberry pi的音频流的回放。

我一直在调查MediaTransport1,MediaPlayer1,MediaControl1,但不幸的是我没有成功。

为了给大家举几个我所做的尝试和错误的例子:

适用于:

代码语言:javascript
复制
dbus-send --system --print-reply --dest=org.bluez /org/bluez/hci0/dev_C8_85_50_B1_C8_6B org.bluez.MediaPlayer1.Pause

我收到了:

代码语言:javascript
复制
Error org.freedesktop.DBus.Error.UnknownMethod: Method "Pause" with signature "" on interface "org.bluez.MediaPlayer1" doesn't exist

代码语言:javascript
复制
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

我收到

代码语言:javascript
复制
Error: org.freedesktop.DBus.Error.InvalidSignature
Invalid signature for 'Volume'

此外,我还找到了一个我认为可以用来构建自己的脚本作为示例这里的播放器,但是我有一个错误:

代码语言:javascript
复制
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

当我进行自我反省

代码语言:javascript
复制
dbus-send --system --print-reply --dest=org.bluez /org/bluez/hci0 org.freedesktop.DBus.Introspectable.Introspect

我得到了他的:

代码语言:javascript
复制
<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>

有人能帮我解决这个问题吗?还是有人知道用覆盆子圆周率控制手机播放音乐的程序?

致以问候。

更新1:非常感谢@Parthiban,因为它运行得非常完美。

此外,我不得不说,我通过以下教程将bluez版本重新安装为5.50:在Raspberry Pi上安装bluez,因为我无法看到/playerX (在我的例子中为0)。在编译源代码之前,我做了一些额外的工作(不确定它是否相关,但并不有害),我添加了.auto_connect = true

所示的avrcp概况:

这里

希望这对每个可能面对我问题的人都有帮助

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-09-07 08:52:51

您需要指定签名来设置卷,如下所示,

代码语言:javascript
复制
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规范中提到的,在使用set时需要指定三个参数,

  1. 接口名称
  2. 财产名称
  3. 属性值变体

对于暂停方法,请使用"org.bluez.MediaPlayer1“访问设备的"org.freedesktop.DBus.Introspectable.Introspect”接口。用于访问“暂停”方法的对象路径是错误的。正如前面提到的这里,您需要使用"[variable prefix]/{hci0,hci1,...}/dev_XX_XX_XX_XX_XX_XX/playerX“。

在你的情况下,应该是,

代码语言:javascript
复制
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“信号上观看。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52212967

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档