在 python 中使用 org.mpris.mediaplayer2.player PlaybackStatus 属性

2024-05-06

The 规格页 http://specifications.freedesktop.org/mpris-spec/latest/Player_Interface.html#summary对于这个特定的接口说:

PlaybackStatus — s (Playback_Status)
.
.
.
May be "Playing", "Paused" or "Stopped".

但当我这样读时:

print "Song %s" % iPlayer.PlaybackStatus

or

if iPlayer.PlaybackStatus == "Playing":
    print "Song playing"

它显示了一个非常奇怪的输出,例如<dbus.proxies._ProxyMethod instance at 0x255f248>

如何访问该变量的字符串值?


您必须致电Get获取属性的方法。该方法返回一个字符串。我执行了以下操作来获取 VLC 播放器的播放状态:

import dbus

bus = dbus.SessionBus()
vlc_media_player_obj = bus.get_object("org.mpris.MediaPlayer2.vlc", "/org/mpris/MediaPlayer2")
props_iface = dbus.Interface(vlc_media_player_obj, 'org.freedesktop.DBus.Properties')
pb_stat = props_iface.Get('org.mpris.MediaPlayer2.Player', 'PlaybackStatus')

在我的例子中(希望在你的例子中),该对象还有一个org.freedesktop.DBus.Properties接口,其中有Get方法,您可以像上面那样调用。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在 python 中使用 org.mpris.mediaplayer2.player PlaybackStatus 属性 的相关文章