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"); }
gboolean mex_music_player_is_playing (MexMusicPlayer *player) { MexMusicPlayerPrivate *priv; g_return_val_if_fail (MEX_IS_MUSIC_PLAYER (player), FALSE); priv = player->priv; return clutter_media_get_playing (priv->player); }
static void mex_music_player_update_playing (MexMusicPlayer *player) { MexMusicPlayerPrivate *priv = player->priv; if (clutter_media_get_playing (priv->player)) mx_stylable_set_style_class (MX_STYLABLE (priv->play_button), "MediaPause"); else mx_stylable_set_style_class (MX_STYLABLE (priv->play_button), "MediaPlay"); }
static void mex_media_controls_play_cb (MxButton *toggle, MexMediaControls *self) { MexMediaControlsPrivate *priv = self->priv; if (priv->media) clutter_media_set_playing (priv->media, !clutter_media_get_playing (priv->media)); }
void mex_music_player_play_toggle (MexMusicPlayer *player) { MexMusicPlayerPrivate *priv; g_return_if_fail (MEX_IS_MUSIC_PLAYER (player)); priv = player->priv; clutter_media_set_playing (priv->player, !clutter_media_get_playing (priv->player)); }
static void media_playing_cb (ClutterMedia *media, GParamSpec *pspec, MexPlayer *player) { MexPlayerPrivate *priv = player->priv; if (!priv->idle_mode) mex_screensaver_inhibit (priv->screensaver); /* reset at_eos flag if a video is now playing */ if (clutter_media_get_playing (media)) priv->at_eos = FALSE; }
static void mex_media_controls_notify_playing_cb (ClutterMedia *media, GParamSpec *pspec, MexMediaControls *self) { MexMediaControlsPrivate *priv = self->priv; MxStylable *button; const gchar *name; if (clutter_media_get_playing (media)) name = "MediaPause"; else name = "MediaPlay"; button = MX_STYLABLE (clutter_script_get_object (priv->script, "play-pause-button")); mx_stylable_set_style_class (button, name); }
static gboolean _start_video_preview (MexContentTile *self) { MexContentTilePrivate *priv = self->priv; GstElement *pipeline; gint gst_flags; const gchar *mimetype, *uri; /* Check we're still focused */ if (!mex_actor_has_focus (CLUTTER_ACTOR (self))) return FALSE; /* Don't play if the main player is still playing.. * too many videos spoil the broth. */ if (clutter_media_get_playing (mex_player_get_clutter_media (mex_player_get_default ()))) return FALSE; mimetype = mex_content_get_metadata (priv->content, MEX_CONTENT_METADATA_MIMETYPE); if ((mimetype) && strncmp (mimetype, "video/", 6) != 0) return FALSE; if (!(uri = mex_content_get_metadata (priv->content, MEX_CONTENT_METADATA_STREAM))) return FALSE; priv->video_preview = clutter_gst_video_texture_new (); pipeline = clutter_gst_video_texture_get_pipeline (CLUTTER_GST_VIDEO_TEXTURE (priv->video_preview)); g_object_get (G_OBJECT (pipeline), "flags", &gst_flags, NULL); gst_flags = 1;//GST_PLAY_FLAG_VIDEO; g_object_set (G_OBJECT (pipeline), "flags", gst_flags, NULL); clutter_gst_video_texture_set_idle_material (CLUTTER_GST_VIDEO_TEXTURE (priv->video_preview), NULL); g_signal_connect (priv->video_preview, "eos", G_CALLBACK (_stop_video_eos), self); clutter_actor_set_opacity (priv->video_preview, 0); g_object_ref (priv->image); clutter_actor_remove_child (CLUTTER_ACTOR (self), priv->image); clutter_actor_add_child (CLUTTER_ACTOR (self), priv->video_preview); clutter_actor_animate (priv->video_preview, CLUTTER_LINEAR, 500, "opacity", 0xff, NULL); clutter_actor_set_size (priv->video_preview, (gfloat)priv->thumb_width, (gfloat)priv->thumb_height); clutter_media_set_uri (CLUTTER_MEDIA (priv->video_preview), uri); clutter_media_set_playing (CLUTTER_MEDIA (priv->video_preview), TRUE); if (priv->stop_video_preview <= 0) priv->stop_video_preview = g_timeout_add_seconds (180, (GSourceFunc)_stop_video_preview, self); return FALSE; }
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; }