Exemple #1
0
static void
player_forward_rewind (MexPlayer *player, gboolean increment)
{
  MexPlayerPrivate *priv = player->priv;

  gdouble duration;
  gfloat progress;

  duration = clutter_media_get_duration (priv->media);
  progress = clutter_media_get_progress (priv->media);

  /* If/when clutter gst supports trickmode we could implement
   *  that here instead
   * http://bugzilla.clutter-project.org/show_bug.cgi?id=2634
   */

  if (increment)
    progress = MIN (1.0, ((duration * progress) + 10) / duration);
  else
    progress = MAX (0.0, ((duration * progress) - 10) / duration);

  mex_player_set_controls_visible (player, TRUE);

  clutter_media_set_progress (priv->media, progress);
}
static gboolean
key_press_timeout_cb (gpointer data)
{
    MexMediaControlsPrivate *priv = MEX_MEDIA_CONTROLS (data)->priv;
    gdouble duration;
    gdouble change;
    gfloat progress;

    priv->long_press_activated = TRUE;

    priv->key_press_count++;

    duration = clutter_media_get_duration (priv->media);
    progress = clutter_media_get_progress (priv->media);

    if (priv->key_press_count >= 10)
        change = 60;
    else
        change = 10;

    if (priv->increment)
        progress = MIN (1.0, ((duration * progress) + change) / duration);
    else
        progress = MAX (0.0, ((duration * progress) - change) / duration);

    clutter_media_set_progress (priv->media, progress);

    return TRUE;
}
static void
_check_if_seeked (ClutterMedia   *media,
                  GParamSpec     *pspec,
                  MexMprisPlugin *self)
{
  MexMprisPluginPrivate *priv = MEX_MPRIS_PLUGIN (self)->priv;

  if (clutter_gst_player_get_in_seek (CLUTTER_GST_PLAYER (media)))
    {
      gdouble progress, duration;
      gint64 newposition;

      duration = clutter_media_get_duration (media);
      /* progress is in a range of 0.0 1.0 so convert to position in uS */
      progress = clutter_media_get_progress (media);

      newposition = duration * progress * 1000000;

      g_dbus_connection_emit_signal (priv->connection,
                                     NULL, MPRIS_OBJECT_NAME,
                                     MPRIS_PLAYER_INTERFACE, "Seeked",
                                     g_variant_new ("(x)", newposition),
                                     NULL);
    }
}
Exemple #4
0
static int mp_get_position(TPMediaPlayer * mp,double * seconds)
{
    USERDATA(mp);
    CM(ud);

    *seconds=clutter_media_get_duration(cm) * clutter_media_get_progress(cm);
    return 0;
}
Exemple #5
0
static void
media_update_progress (GObject    *gobject,
                       GParamSpec *pspec,
                       MexPlayer  *player)
{
  MexPlayerPrivate *priv = player->priv;

  if (!priv->at_eos)
    priv->current_position = clutter_media_get_progress (priv->media);
}
static void
mex_media_controls_notify_progress_cb (ClutterMedia     *media,
                                       GParamSpec       *pspec,
                                       MexMediaControls *self)
{
    MexMediaControlsPrivate *priv = self->priv;
    MxLabel *label;
    gchar *text;
    gdouble length, progress_s;
    gfloat progress;
    gint len_h, len_m, len_s, pos_h, pos_m, pos_s;

    if (priv->show_description)
        return;

    progress = clutter_media_get_progress (media);
    length = clutter_media_get_duration (media);

    len_h = length / 3600;
    len_m = (length - (len_h * 3600)) / 60;
    len_s = (length - (len_h * 3600) - (len_m * 60));

    progress_s = length * progress;

    pos_h = progress_s / 3600;
    pos_m = (progress_s - (pos_h * 3600)) / 60;
    pos_s = (progress_s - (pos_h * 3600) - (pos_m * 60));

    g_signal_handlers_block_by_func (priv->slider, slider_value_changed_cb, self);
    mx_slider_set_value (MX_SLIDER (priv->slider), progress);
    g_signal_handlers_unblock_by_func (priv->slider, slider_value_changed_cb,
                                       self);

    if (len_h > 0)
        text = g_strdup_printf ("%02d:%02d:%02d / %02d:%02d:%02d",
                                pos_h, pos_m, pos_s, len_h, len_m, len_s);
    else
        text = g_strdup_printf ("%02d:%02d / %02d:%02d",
                                pos_m, pos_s, len_m, len_s);

    label = (MxLabel*) clutter_script_get_object (priv->script, "progress-label");
    mx_label_set_text (label, text);
    g_free (text);
}
void
mex_music_player_seek_us (MexMusicPlayer *player, gint64 seek_offset_us)
{
  MexMusicPlayerPrivate *priv;
  gdouble duration_us, progress, new_progress;

  g_return_if_fail (MEX_IS_MUSIC_PLAYER (player));

  priv = player->priv;

  duration_us = clutter_media_get_duration (priv->player) * 1000000;
  progress = clutter_media_get_progress (priv->player) * duration_us;

  new_progress = (progress + seek_offset_us) / duration_us;

  if (new_progress < 0.0)
    mex_music_player_previous (player);
  else if (new_progress > 1.0)
    mex_music_player_next (player);
  else
    clutter_media_set_progress (priv->player, new_progress);
}
static void
mex_music_player_update_progress (MexMusicPlayer *player)
{
  MexMusicPlayerPrivate *priv = player->priv;
  ClutterActor *label, *slider;
  gchar *text;
  gdouble progress, duration;

  progress = clutter_media_get_progress (priv->player);
  duration = clutter_media_get_duration (priv->player);

  label = mex_script_get_actor (priv->script, "progress-label");
  slider = mex_script_get_actor (priv->script, "progress-slider");

  g_signal_handler_block (slider, priv->slider_notify_id);
  mx_slider_set_value (MX_SLIDER (slider), progress);
  g_signal_handler_unblock (slider, priv->slider_notify_id);

  text = mex_metadata_utils_create_progress_string (progress, duration);
  mx_label_set_text (MX_LABEL (label), text);
  g_free (text);
}
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;
}