Make play button from headset toggle mpris play/pause
I'd find it very useful if the play button on headsets was able to toggle play/pause of the currently active mpris player. Then I could quickly toggle music / podcast playback from the headset without pulling out the phone.
The button is available as XF86AudioPlay
, so with the following patch, I can get phosh to log a message when the button is pressed.
The mpris code to check if the player can play/pause, and to actually do it, is used in src/media-player.c
already (e.g. phosh_mpris_dbus_media_player2_player_call_play_pause
). However, it needs the dbus player object as first parameter, which isn't available in src/settings.c
.
If this feature is wanted, it would be great if you could give me a pointer of how it should be implemented.
--- a/src/settings.c
+++ b/src/settings.c
@@ -79,10 +79,12 @@ G_DEFINE_TYPE (PhoshSettings, phosh_settings, GTK_TYPE_BIN)
static void raise_volume (GSimpleAction *action, GVariant *param, gpointer self);
static void lower_volume (GSimpleAction *action, GVariant *param, gpointer self);
+static void play (GSimpleAction *action, GVariant *param, gpointer self);
const GActionEntry action_entries[] = {
{ "XF86AudioLowerVolume", lower_volume, },
{ "XF86AudioRaiseVolume", raise_volume, },
+ { "XF86AudioPlay", play, },
};
static void
@@ -224,6 +226,14 @@ raise_volume (GSimpleAction *action, GVariant *param, gpointer self)
change_volume (PHOSH_SETTINGS (self), 1);
}
+static void
+play (GSimpleAction *action, GVariant *param, gpointer self)
+{
+ g_return_if_fail (PHOSH_IS_SETTINGS (self));
+
+ g_debug ("Play button pressed");
+}
+
static void
update_output_vol_bar (PhoshSettings *self)