static int mp_set_audio_mute(TPMediaPlayer * mp,int mute) { USERDATA(mp); CM(ud); int old_mute = ud->mute; ud->mute = mute ? 1 : 0; if ( old_mute != ud->mute ) { if ( ud->mute ) { ud->volume = clutter_media_get_audio_volume(cm); clutter_media_set_audio_volume(cm,0); } else { clutter_media_set_audio_volume(cm,ud->volume); ud->volume = 0; } } return 0; }
static void on_audio_volume_changed (ClutterMedia *media, GParamSpec *pspec, MexVolumeControl *self) { MexVolumeControlPrivate *priv = self->priv; static gboolean first_notification = TRUE; gdouble new_volume; if ((clutter_media_get_playing (priv->music) && priv->music == media) || (clutter_media_get_playing (priv->media) && priv->media == media)) new_volume = clutter_media_get_audio_volume (media); else return; if (fabs (priv->vol_value - new_volume) < 0.01) return; priv->vol_value = CLAMP (new_volume, 0.0, 1.0); update_style_class (self); /* Pulse audio sends a notification when playing a stream for the first * time. We want to ignore this to we don't show the volume control when * playing the first stream and opening the pulse connection */ if (G_UNLIKELY (first_notification)) { first_notification = FALSE; return; } g_object_notify (G_OBJECT (self), "volume"); }
static void mex_volume_control_init (MexVolumeControl *self) { MexVolumeControlPrivate *priv = self->priv = VOLUME_CONTROL_PRIVATE (self); gchar *new_style_class; MexPlayer *player; MexMusicPlayer *music; player = mex_player_get_default (); priv->media = mex_player_get_clutter_media (player); music = mex_music_player_get_default (); priv->music = mex_music_player_get_clutter_media (music); priv->volume = mx_button_new (); mx_widget_set_disabled (MX_WIDGET (priv->volume), TRUE); priv->vol_value = clutter_media_get_audio_volume (priv->media); /* The media sound can also be changed from another process changint the * stream audio with pulse audio, adjust the volume on those changes */ g_signal_connect (priv->media, "notify::audio-volume", G_CALLBACK (on_audio_volume_changed), self); g_signal_connect (priv->music, "notify::audio-volume", G_CALLBACK (on_audio_volume_changed), self); new_style_class = g_strdup_printf ("volume-%.0f", priv->vol_value * 10); mx_stylable_set_style_class (MX_STYLABLE (priv->volume), new_style_class); g_free (new_style_class); clutter_actor_add_child (CLUTTER_ACTOR (self), priv->volume); }
static int mp_get_audio_volume(TPMediaPlayer * mp,double * volume) { USERDATA(mp); CM(ud); if ( ud->mute ) { * volume = ud->volume; } else { *volume=clutter_media_get_audio_volume(cm); } return 0; }
static GVariant * _get_player_property_cb (GDBusConnection *connection, const gchar *sender, const gchar *object_path, const gchar *interface_name, const gchar *property_name, GError **error, gpointer user_data) { MexMprisPluginPrivate *priv = MEX_MPRIS_PLUGIN (user_data)->priv; ClutterMedia *media; GVariant *v = NULL; if (mex_music_player_is_playing (priv->music)) media = mex_music_player_get_clutter_media (priv->music); else media = mex_player_get_clutter_media (priv->player); if (g_strcmp0 ("PlaybackStatus", property_name) == 0) { /* Doesn't map to ClutterMedia straight away so try to emulate. * Playback could theoretically be paused at progress 0.0 but well ...*/ gdouble progress = clutter_media_get_progress (media); gboolean playing = clutter_media_get_playing (media); if (playing) v = g_variant_new_string ("Playing"); else if (progress != 0) v = g_variant_new_string ("Paused"); else v = g_variant_new_string ("Stopped"); } else if (g_strcmp0 ("LoopStatus", property_name) == 0) v = g_variant_new_string ("None"); else if (g_strcmp0 ("Rate", property_name) == 0 || g_strcmp0 ("MinimumRate", property_name) == 0 || g_strcmp0 ("MinimumRate", property_name) == 0 ) v = g_variant_new_double (1.0); else if (g_strcmp0 ("Shuffle", property_name) == 0) v = g_variant_new_boolean (FALSE); else if (g_strcmp0 ("Volume", property_name) == 0) v = g_variant_new_double (clutter_media_get_audio_volume (media)); else if (g_strcmp0 ("Position", property_name) == 0) { gdouble duration_s = clutter_media_get_duration (media); gdouble progress_rel = clutter_media_get_progress (media); gint64 position_ms = duration_s * 1000000 * progress_rel; v = g_variant_new_int64 (position_ms); } else if (g_strcmp0 ("CanGoNext", property_name) == 0 || g_strcmp0 ("CanGoPrevious", property_name) == 0 || g_strcmp0 ("CanPlay", property_name) == 0 || g_strcmp0 ("CanControl", property_name) == 0 || g_strcmp0 ("CanPause", property_name) == 0) v = g_variant_new_boolean (TRUE); else if (g_strcmp0 ("CanSeek", property_name) == 0) v = g_variant_new_boolean (clutter_media_get_can_seek (media)); if (v) return v; g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_NOT_SUPPORTED, "Property %s.%s not supported", interface_name, property_name); return NULL; }