aboutsummaryrefslogtreecommitdiff
path: root/src/media-player.vala
diff options
context:
space:
mode:
authorLars Uebernickel <lars.uebernickel@canonical.com>2013-07-06 17:00:57 -0400
committerLars Uebernickel <lars.uebernickel@canonical.com>2013-07-06 17:00:57 -0400
commit5d9874b1df7ea7c0f7e1c2764b4d8cbd2bad7684 (patch)
treef88c357e80a127dcbebe377931047b2ca14c7506 /src/media-player.vala
parent99b12cdd16a1fea2740b812d697bea887df2b5bd (diff)
downloadayatana-indicator-sound-5d9874b1df7ea7c0f7e1c2764b4d8cbd2bad7684.tar.gz
ayatana-indicator-sound-5d9874b1df7ea7c0f7e1c2764b4d8cbd2bad7684.tar.bz2
ayatana-indicator-sound-5d9874b1df7ea7c0f7e1c2764b4d8cbd2bad7684.zip
Launch player when the play action is activated
Diffstat (limited to 'src/media-player.vala')
-rw-r--r--src/media-player.vala15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/media-player.vala b/src/media-player.vala
index 5b59efb..68a0b38 100644
--- a/src/media-player.vala
+++ b/src/media-player.vala
@@ -133,8 +133,13 @@ public class MediaPlayer: Object {
* Toggles playing status.
*/
public void play_pause () {
- if (this.proxy != null)
+ if (this.proxy != null) {
this.proxy.PlayPause.begin ();
+ }
+ else if (this.state != "Launching") {
+ this.play_when_attached = true;
+ this.launch ();
+ }
}
/**
@@ -156,6 +161,7 @@ public class MediaPlayer: Object {
DesktopAppInfo appinfo;
MprisPlayer? proxy;
string _dbus_name;
+ bool play_when_attached = false;
void got_proxy (Object? obj, AsyncResult res) {
try {
@@ -169,6 +175,13 @@ public class MediaPlayer: Object {
this.notify_property ("is-running");
this.state = this.proxy.PlaybackStatus;
this.update_current_track (gproxy.get_cached_property ("Metadata"));
+
+ if (this.play_when_attached) {
+ /* wait a little before calling PlayPause, some players need some time to
+ set themselves up */
+ Timeout.add (1000, () => { proxy.PlayPause.begin (); return false; } );
+ this.play_when_attached = false;
+ }
}
catch (Error e) {
this._dbus_name = null;