问题描述
我已经检查了以下链接:如何使用python处理dbus接口的属性.但是,那只列出了一个API ...但是我不知道该API的来源.
I have already checked this link: How to handle properties of a dbus interface with python. However, that only lists an API... but I don't know where that API comes from.
我刚开始在python上使用dbus(对此感到非常兴奋,说实话^ __ ^对我发现的文档不太满意),我想知道是否可以得到一些示例代码.
I just started working with dbus (pretty excited about this, to be honest ^__^ just not too happy with the documentation I've found) on python and I was wondering if I could just get some sample code.
我正在使用专门用于Rhythmbox的MPRIS,尽管它对所有人都应该相同.
I'm using MPRIS specifically for Rhythmbox, although it 'should' be the same for all.
通过执行以下操作,我知道我可以使用这些方法并从中获得乐趣:
I know I can access and have fun witht he methods by doing the following:
import dbus
bus = dbus.SessionBus()
proxy = bus.get_object('org.mpris.MediaPlayer2.rhythmbox','/org/mpris/MediaPlayer2')
player = dbus.Interface(proxy, 'org.mpris.MediaPlayer2.Player')
playlists = dbus.Interface(proxy, 'org.mpris.MediaPlayer2.Playlists')
tracklist = dbus.Interface(proxy, 'org.mpris.MediaPlayer2.TrackList')
但是,我希望了解有关属性的信息.一些示例代码就可以了:)谢谢!
However, I wish to know about properties. Some sample code will suffice :) Thanks!
推荐答案
找到了方法.
proxy = bus.get_object('org.mpris.MediaPlayer2.rhythmbox','/org/mpris/MediaPlayer2')
properties_manager = dbus.Interface(proxy, 'org.freedesktop.DBus.Properties')
properties_manager.Set('org.mpris.MediaPlayer2.Player', 'Volume', 100.0)
curr_volume = properties_manager.Get('org.mpris.MediaPlayer2.Player', 'Volume')
确实非常简单:)我认为这样会很简单.
Pretty simple indeed :) I thought it would be simple like this.
这篇关于MPRIS + Python(dbus):读写属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!