16

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!

Community
  • 1
  • 1
Mamsaac
  • 6,173
  • 3
  • 21
  • 30

1 Answers1

23

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.

Mendhak
  • 8,194
  • 5
  • 47
  • 64
Mamsaac
  • 6,173
  • 3
  • 21
  • 30
  • Were you able to write metadata, such as setting a song's rating? – Mendhak May 13 '12 at 00:04
  • 2
    Effective, but what a pain! You'd think there'd be an easier way. – Trebor Rude Jan 25 '14 at 00:47
  • 1
    By the way, if you found out how to do this via some online resource (as opposed to looking through source code), could you post the link? – Trebor Rude Jan 25 '14 at 00:49
  • 1
    Won't lie, I don't remember how I found out. I can't even find the source code for this project (I wanted to continue it just 2 months ago). It is -very- likely that I checked through the source code, though. – Mamsaac Jan 27 '14 at 03:26