diff options
Diffstat (limited to 'lib/mpris/player.vala')
-rw-r--r-- | lib/mpris/player.vala | 72 |
1 files changed, 37 insertions, 35 deletions
diff --git a/lib/mpris/player.vala b/lib/mpris/player.vala index b72c15e..2050f61 100644 --- a/lib/mpris/player.vala +++ b/lib/mpris/player.vala @@ -9,7 +9,12 @@ public class AstalMpris.Player : Object { private IPlayer proxy; private uint pollid; // periodically notify position - // identifiers + internal signal void appeared() { available = true; } + internal signal void closed() { available = false; } + + /** + * Full dbus namae of this player. + */ public string bus_name { owned get; private set; } /** @@ -37,7 +42,7 @@ public class AstalMpris.Player : Object { * The media player may refuse to allow clients to shut it down. * In this case, the [[email protected]:can_quit] property is false and this method does nothing. */ - public void quit() throws Error { + public void quit() { try { proxy.quit(); } catch (Error err) { critical(err.message); } } @@ -559,15 +564,33 @@ public class AstalMpris.Player : Object { } construct { - try { - try_proxy(); - sync(); - } catch (Error error) { - critical(error.message); - } + notify["bus-name"].connect(() => { + try { + setup_proxy(); + setup_position_poll(); + sync(); + } catch (Error error) { + critical(error.message); + } + }); } - private void try_proxy() throws Error { + private void setup_position_poll() { + var current_position = position; + + pollid = Timeout.add_seconds(1, () => { + if (!available) + return Source.CONTINUE; + + if (position >= 0 && current_position != position) { + current_position = position; + notify_property("position"); + } + return Source.CONTINUE; + }, Priority.DEFAULT); + } + + private void setup_proxy() throws Error { if (proxy != null) return; @@ -577,28 +600,19 @@ public class AstalMpris.Player : Object { "/org/mpris/MediaPlayer2" ); - if (proxy.g_name_owner != null) - available = false; + if (proxy.g_name_owner != null) { + appeared(); + } proxy.notify["g-name-owner"].connect(() => { if (proxy.g_name_owner != null) { - available = true; + appeared(); } else { - available = false; + closed(); } }); proxy.g_properties_changed.connect(sync); - - pollid = Timeout.add_seconds(1, () => { - if (!available) - return Source.CONTINUE; - - if (position >= 0) { - notify_property("position"); - } - return Source.CONTINUE; - }, Priority.DEFAULT); } ~Player() { @@ -622,18 +636,6 @@ public enum AstalMpris.PlaybackStatus { return STOPPED; } } - - internal string to_string() { - switch (this) { - case PLAYING: - return "Playing"; - case PAUSED: - return "Paused"; - case STOPPED: - default: - return "Stopped"; - } - } } public enum AstalMpris.Loop { |