此特定接口的规范页面显示:
PlaybackStatus — s (Playback_Status)
.
.
.
May be "Playing", "Paused" or "Stopped".
但当我这样读的时候:
print "Song %s" % iPlayer.PlaybackStatus
或
if iPlayer.PlaybackStatus == "Playing":
print "Song playing"
它显示了一个非常奇怪的输出,类似于<dbus.proxies._ProxyMethod instance at 0x255f248>
如何访问此变量的String值?
您必须调用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
方法,您可以如上所述调用它。