aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/media-player.vala34
-rw-r--r--src/service.vala24
2 files changed, 56 insertions, 2 deletions
diff --git a/src/media-player.vala b/src/media-player.vala
index 717d135..b767268 100644
--- a/src/media-player.vala
+++ b/src/media-player.vala
@@ -74,6 +74,12 @@ public class MediaPlayer: Object {
}
}
+ public bool is_playing {
+ get {
+ return this.proxy != null && this.proxy.PlaybackStatus == "Playing";
+ }
+ }
+
public class Track : Object {
public string artist { get; construct; }
public string title { get; construct; }
@@ -132,6 +138,30 @@ public class MediaPlayer: Object {
}
}
+ /**
+ * Toggles playing status.
+ */
+ public void play_pause () {
+ if (this.proxy != null)
+ this.proxy.PlayPause.begin ();
+ }
+
+ /**
+ * Skips to the next track.
+ */
+ public void next () {
+ if (this.proxy != null)
+ this.proxy.Next.begin ();
+ }
+
+ /**
+ * Skips to the previous track.
+ */
+ public void previous () {
+ if (this.proxy != null)
+ this.proxy.Previous.begin ();
+ }
+
DesktopAppInfo appinfo;
MprisPlayer? proxy;
string _dbus_name;
@@ -170,8 +200,10 @@ public class MediaPlayer: Object {
}
void proxy_properties_changed (DBusProxy proxy, Variant changed_properties, string[] invalidated_properties) {
- if (changed_properties.lookup ("PlaybackStatus", "s", null))
+ if (changed_properties.lookup ("PlaybackStatus", "s", null)) {
this.notify_property ("state");
+ this.notify_property ("is-running");
+ }
var metadata = changed_properties.lookup_value ("Metadata", new VariantType ("a{sv}"));
if (metadata != null)
diff --git a/src/service.vala b/src/service.vala
index fe95ab8..ad9698e 100644
--- a/src/service.vala
+++ b/src/service.vala
@@ -61,7 +61,7 @@ public class IndicatorSound.Service {
const ActionEntry[] action_entries = {
{ "root", null, null, "{ 'icon': <'audio-volume-high-panel'> }", null },
- { "settings", activate_settings, null, null, null }
+ { "settings", activate_settings, null, null, null },
};
MainLoop loop;
@@ -200,8 +200,15 @@ public class IndicatorSound.Service {
player_item.set_attribute ("x-canonical-type", "s", "com.canonical.unity.media-player");
player_item.set_attribute_value ("icon", g_icon_serialize (player.icon));
+ var playback_item = new MenuItem (null, null);
+ playback_item.set_attribute ("x-canonical-type", "s", "com.canonical.unity.playback-item");
+ playback_item.set_attribute ("x-canonical-play-action", "s", "indicator.play." + player.id);
+ playback_item.set_attribute ("x-canonical-next-action", "s", "indicator.next." + player.id);
+ playback_item.set_attribute ("x-canonical-previous-action", "s", "indicator.previous." + player.id);
+
var section = new Menu ();
section.append_item (player_item);
+ section.append_item (playback_item);
this.menu.insert_section (this.menu.get_n_items () -1, null, section);
@@ -209,6 +216,18 @@ public class IndicatorSound.Service {
action.activate.connect ( () => { player.launch (); });
this.actions.insert (action);
+ var play_action = new SimpleAction.stateful ("play." + player.id, null, player.is_playing);
+ play_action.activate.connect ( () => player.play_pause () );
+ this.actions.insert (play_action);
+
+ var next_action = new SimpleAction ("next." + player.id, null);
+ next_action.activate.connect ( () => player.next () );
+ this.actions.insert (next_action);
+
+ var prev_action = new SimpleAction ("previous." + player.id, null);
+ prev_action.activate.connect ( () => player.previous () );
+ this.actions.insert (prev_action);
+
player.notify.connect (this.eventually_update_player_actions);
this.update_preferred_players ();
@@ -216,6 +235,9 @@ public class IndicatorSound.Service {
void player_removed (MediaPlayer player) {
this.actions.remove (player.id);
+ this.actions.remove ("play." + player.id);
+ this.actions.remove ("next." + player.id);
+ this.actions.remove ("previous." + player.id);
int n = this.menu.get_n_items ();
for (int i = 0; i < n; i++) {