MPRIS + Python (dbus): reading and writing properties

筅森魡賤 提交于 2019-12-04 08:26:43

问题


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.

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.

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!


回答1:


Found how.

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.



来源:https://stackoverflow.com/questions/9493494/mpris-python-dbus-reading-and-writing-properties

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