music_track_listener: recognize playing song
when listener is enabled
This commit is contained in:
parent
b56f9c6fac
commit
b8444fec64
|
@ -2099,11 +2099,13 @@ class Interface:
|
||||||
if not self.music_track_changed_signal:
|
if not self.music_track_changed_signal:
|
||||||
self.music_track_changed_signal = listener.connect(
|
self.music_track_changed_signal = listener.connect(
|
||||||
'music-track-changed', self.music_track_changed)
|
'music-track-changed', self.music_track_changed)
|
||||||
|
listener.start()
|
||||||
|
|
||||||
def disable_music_listener(self):
|
def disable_music_listener(self):
|
||||||
listener = MusicTrackListener.get()
|
listener = MusicTrackListener.get()
|
||||||
listener.disconnect(self.music_track_changed_signal)
|
listener.disconnect(self.music_track_changed_signal)
|
||||||
self.music_track_changed_signal = None
|
self.music_track_changed_signal = None
|
||||||
|
listener.stop()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def music_track_changed(unused_listener, music_track_info, account=None):
|
def music_track_changed(unused_listener, music_track_info, account=None):
|
||||||
|
|
|
@ -55,6 +55,7 @@ class MusicTrackListener(GObject.GObject):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.players = {}
|
self.players = {}
|
||||||
|
|
||||||
|
def start(self):
|
||||||
proxy = Gio.DBusProxy.new_for_bus_sync(
|
proxy = Gio.DBusProxy.new_for_bus_sync(
|
||||||
Gio.BusType.SESSION,
|
Gio.BusType.SESSION,
|
||||||
Gio.DBusProxyFlags.NONE,
|
Gio.DBusProxyFlags.NONE,
|
||||||
|
@ -92,6 +93,11 @@ class MusicTrackListener(GObject.GObject):
|
||||||
if name.startswith(MPRIS_PLAYER_PREFIX):
|
if name.startswith(MPRIS_PLAYER_PREFIX):
|
||||||
self._add_player(name)
|
self._add_player(name)
|
||||||
|
|
||||||
|
def stop(self):
|
||||||
|
for name in list(self.players):
|
||||||
|
if name.startswith(MPRIS_PLAYER_PREFIX):
|
||||||
|
self._remove_player(name)
|
||||||
|
|
||||||
def _signal_name_owner_changed(self, connection, sender_name, object_path,
|
def _signal_name_owner_changed(self, connection, sender_name, object_path,
|
||||||
interface_name, signal_name, parameters, *user_data):
|
interface_name, signal_name, parameters, *user_data):
|
||||||
name, oldOwner, newOwner = parameters
|
name, oldOwner, newOwner = parameters
|
||||||
|
@ -204,4 +210,5 @@ if __name__ == '__main__':
|
||||||
print(music_track_info.title)
|
print(music_track_info.title)
|
||||||
listener = MusicTrackListener.get()
|
listener = MusicTrackListener.get()
|
||||||
listener.connect('music-track-changed', music_track_change_cb)
|
listener.connect('music-track-changed', music_track_change_cb)
|
||||||
|
listener.start()
|
||||||
GLib.MainLoop().run()
|
GLib.MainLoop().run()
|
||||||
|
|
Loading…
Reference in New Issue