using org.mpris.mediaplayer2.player PlaybackStatus property in python

◇◆丶佛笑我妖孽 提交于 2019-12-11 06:17:33

问题


The Specification page for this particular interface says:

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

But when i read it like this:

print "Song %s" % iPlayer.PlaybackStatus

or

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

It shows a very strange output like <dbus.proxies._ProxyMethod instance at 0x255f248>

How can I access the String value of this variable?


回答1:


You have to call the Get method to get the property. The method returns a string. I did the following to get playback status of VLC player:

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')

In my case (and hopefully in yours), the object also had a org.freedesktop.DBus.Properties interface, which has the Get method, which you can call as above.



来源:https://stackoverflow.com/questions/23324841/using-org-mpris-mediaplayer2-player-playbackstatus-property-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!