[js] add mpris api for music players

This commit is contained in:
Yann Leboulanger 2007-12-08 11:22:55 +00:00
parent 015d3221e1
commit 1b212ce90d
1 changed files with 20 additions and 1 deletions

View File

@ -51,6 +51,13 @@ class MusicTrackListener(gobject.GObject):
bus = dbus.SessionBus()
## MPRIS
bus.add_signal_receiver(self._mpris_music_track_change_cb, 'TrackChange',
'org.freedesktop.MediaPlayer')
bus.add_signal_receiver(self._player_playing_changed_cb, 'StatusChange',
'org.freedesktop.MediaPlayer')
## Muine
bus.add_signal_receiver(self._muine_music_track_change_cb, 'SongChanged',
'org.gnome.Muine.Player')
@ -116,6 +123,18 @@ class MusicTrackListener(gobject.GObject):
if b == 'rb:stream-song-title':
self.emit('music-track-changed', self._last_playing_music)
def _mpris_properties_extract(self, song):
info = MusicTrackInfo()
info.title = song['title']
info.album = song['album']
info.artist = song['artist']
info.duration = int(song['length'])
return info
def _mpris_music_track_change_cb(self, arg):
info = self._mpris_properties_extract(arg)
self.emit('music-track-changed', info)
def _muine_properties_extract(self, song_string):
d = dict((x.strip() for x in s1.split(':', 1)) for s1 in \
song_string.split('\n'))