Пример #1
0
static void
_player_method_cb (GDBusConnection       *connection,
                   const gchar           *sender,
                   const gchar           *object_path,
                   const gchar           *interface_name,
                   const gchar           *method_name,
                   GVariant              *parameters,
                   GDBusMethodInvocation *invocation,
                   MexMprisPlugin        *self)
{
  MexMprisPluginPrivate *priv = MEX_MPRIS_PLUGIN (self)->priv;

 if (g_strcmp0 (method_name, "Next") == 0)
   mex_player_next (priv->player);

 else if (g_strcmp0 (method_name, "OpenUri") == 0)
   {
     const gchar *uri;
     g_variant_get (parameters, "(s)", &uri);
     mex_player_set_uri (priv->player, uri);
   }

 else if (g_strcmp0 (method_name, "Pause") == 0)
   mex_player_pause (priv->player);

 else if (g_strcmp0 (method_name, "Play") == 0)
   mex_player_play (priv->player);

 else if (g_strcmp0 (method_name, "PlayPause") == 0)
     mex_player_playpause (priv->player);

 else if (g_strcmp0 (method_name, "Previous") == 0)
   mex_player_previous (priv->player);

 else if (g_strcmp0 (method_name, "Seek") == 0)
   {
     gint64 seek_offset;
     g_variant_get (parameters, "(x)", &seek_offset);
     mex_player_seek_us (priv->player, seek_offset);
   }

 else if (g_strcmp0 (method_name, "Stop") == 0)
   mex_player_quit (priv->player);

 else
     g_message ("Unhandled MPRIS Player method %s", method_name);

  g_dbus_method_invocation_return_value (invocation, NULL);
}
Пример #2
0
static void
_player_method_cb (GDBusConnection       *connection,
                   const gchar           *sender,
                   const gchar           *object_path,
                   const gchar           *interface_name,
                   const gchar           *method_name,
                   GVariant              *parameters,
                   GDBusMethodInvocation *invocation,
                   MexMprisPlugin        *self)
{
  MexMprisPluginPrivate *priv = MEX_MPRIS_PLUGIN (self)->priv;

 if (g_strcmp0 (method_name, "Next") == 0)
   {
     if (CLUTTER_ACTOR_IS_VISIBLE (CLUTTER_ACTOR (priv->music)) ||
         mex_music_player_is_playing (priv->music))
       mex_music_player_next (priv->music);
     else
       mex_player_next (priv->player);
   }
 else if (g_strcmp0 (method_name, "OpenUri") == 0)
   {
     const gchar *uri;
     char *pfx;

     g_variant_get (parameters, "(s)", &uri);

     if ((pfx = _content_mime_prefix (uri)))
       {
         if (!strcmp (pfx, "audio"))
           mex_music_player_set_uri (priv->music, uri);
         else if (!strcmp (pfx, "image"))
           g_warning ("Mpris image playback is not implemented");
         else
           mex_player_set_uri (priv->player, uri);
       }
     else
       mex_player_set_uri (priv->player, uri);
   }
 else if (g_strcmp0 (method_name, "Pause") == 0)
   {
     if (CLUTTER_ACTOR_IS_VISIBLE (CLUTTER_ACTOR (priv->music)) ||
         mex_music_player_is_playing (priv->music))
       mex_music_player_stop (priv->music);
     else
       mex_player_pause (priv->player);
   }
 else if (g_strcmp0 (method_name, "Play") == 0)
   {
     if (CLUTTER_ACTOR_IS_VISIBLE (CLUTTER_ACTOR (priv->music)) ||
         mex_music_player_is_playing (priv->music))
       mex_music_player_play (priv->music);
     else
       mex_player_play (priv->player);
   }
 else if (g_strcmp0 (method_name, "PlayPause") == 0)
   {
     if (CLUTTER_ACTOR_IS_VISIBLE (CLUTTER_ACTOR (priv->music)) ||
         mex_music_player_is_playing (priv->music))
       mex_music_player_play_toggle (priv->music);
     else
       mex_player_playpause (priv->player);
   }
 else if (g_strcmp0 (method_name, "Previous") == 0)
   {
     if (CLUTTER_ACTOR_IS_VISIBLE (CLUTTER_ACTOR (priv->music)) ||
         mex_music_player_is_playing (priv->music))
       mex_music_player_previous (priv->music);
     else
       mex_player_previous (priv->player);
   }
 else if (g_strcmp0 (method_name, "Seek") == 0)
   {
     gint64 seek_offset;
     g_variant_get (parameters, "(x)", &seek_offset);

     if (CLUTTER_ACTOR_IS_VISIBLE (CLUTTER_ACTOR (priv->music)) ||
         mex_music_player_is_playing (priv->music))
       mex_music_player_seek_us (priv->music, seek_offset);
     else
       mex_player_seek_us (priv->player, seek_offset);
   }
 else if (g_strcmp0 (method_name, "Stop") == 0)
   {
     if (CLUTTER_ACTOR_IS_VISIBLE (CLUTTER_ACTOR (priv->music)) ||
         mex_music_player_is_playing (priv->music))
       mex_music_player_quit (priv->music);
     else
       mex_player_quit (priv->player);
   }
 else
     g_message ("Unhandled MPRIS Player method %s", method_name);

  g_dbus_method_invocation_return_value (invocation, NULL);
}