MPRIS + Python (dbus): reading and writing properties

Asked
Active3 hr before
Viewed126 times

8 Answers

python
90%

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., Meta Stack Overflow ,Stack Overflow en español,Stack Overflow em Português

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

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.,However, I wish to know about properties. Some sample code will suffice :) Thanks!,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 know I can access and have fun witht he methods by doing the following:

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')
load more v
72%

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.,So better use is to convert date into Long while writing, and read Long and pass to Date constructor to get Date. See below code ,Pretty simple indeed :) I thought it would be simple like this.,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')
load more v
65%

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.,Get answers to millions of questions and give back by sharing your knowledge with others.,However, I wish to know about properties. Some sample code will suffice :) Thanks!,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 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')
load more v
75%

If the playback progresses in a way that is inconstistant with the Rate property, the Seeked signal is emited. , If the CanSeek property is false, this has no effect. , When playing, the position progresses according to the rate property. ,The current playback rate.

org.freedesktop.DBus.Properties.PropertiesChanged
load more v
40%

I'm trying to write a small Python script that checks whether Spotify is running, playing, and if it is, returns some metadata about the track that is being played. For that, I'm using the MPRIS interface., DBus MPRIS interface bug. ,And if I launch spotify in a terminal, I get a warning :,This happens using Python 3.5.1 and spotify 1.0.19.106.gb8a7150f.

 

>>>
import dbus >>> bus = dbus.SessionBus() >>> spotify_bus = bus.get_object("org.mpris.MediaPlayer2.spotify", "/org/mpris/MediaPlayer2") >>> properties_interface = dbus.Interface(spotify_bus, 'org.freedesktop.DBus.Properties') >>> properties_interface.Get('org.mpris.MediaPlayer2.Player', 'PlaybackStatus')
load more v
22%

0
60%

Having discovered the MediaPlayer2 object and its 'Player' interface, let's begin by trying to call its PlayPause method:,We can install Clementine in the usual way:,To start, let's introduce our music player of the day, and dbus test candidate, Clementine.,And here's how exploring Clementine's dbus connection looks in it:

We can install Clementine in the usual way:

$ sudo apt update
$ sudo apt install clementine
load more v

Other "python-undefined" queries related to "MPRIS + Python (dbus): reading and writing properties"