Esempio n. 1
0
static gboolean
ol_player_listen_get_music_length (int *len)
{
  if (len == NULL)
    return FALSE;
  if (connection == NULL || proxy == NULL)
    if (!ol_player_listen_init_dbus ())
      return FALSE;
  gint64 buf;
  enum OlPlayerStatus status = ol_player_listen_get_status ();
  if (status == OL_PLAYER_PLAYING)
  {
    if (!ol_dbus_get_int64 (proxy, duration, &buf))
    {
      return FALSE;
    }
    *len = buf*1000;
    //g_free (buf);
    return TRUE;
  }
  else if (status == OL_PLAYER_STOPPED)
  {
    return TRUE;
  }
  else
  {
    return FALSE;
  }
}
Esempio n. 2
0
static gboolean
ol_player_listen_next ()
{
  ol_logf (OL_DEBUG, "%s\n", __FUNCTION__);
  if (connection == NULL || proxy == NULL)
    if (!ol_player_listen_init_dbus ())
      return FALSE;
  return ol_dbus_invoke (proxy, next);
}
Esempio n. 3
0
static gboolean
ol_player_listen_get_music_info (OlMusicInfo *info)
{
  /* ol_log_func (); */
  ol_assert (info != NULL);
  if (connection == NULL || proxy == NULL)
    if (!ol_player_listen_init_dbus ())
    {
      ol_debug ("Initialize dbus proxy failed\n");
      return FALSE;
    }
  gchar *buf;
  enum OlPlayerStatus status = ol_player_listen_get_status ();
  ol_debugf ("  status: %d\n", (int)status);
  if (status == OL_PLAYER_PLAYING)
  {
    ol_music_info_clear (info);
    /* gets the title of current music */
    if (!ol_dbus_get_string (proxy,
                             get_title,
                             &info->title))
    {
      ol_error ("  Get title failed");
    }
    /* gets the artist of current music */
    if (!ol_dbus_get_string (proxy,
                             get_artist,
                             &info->artist))
    {
      ol_error ("  Get artist failed");
    }
    /* gets the album of current music */
    if (!ol_dbus_get_string (proxy,
                             get_album,
                             &info->album))
    {
      ol_error ("  Get album failed");
    }
    /* gets the location of the file */
    if (!ol_dbus_get_string (proxy,
                             get_uri,
                             &info->uri))
    {
      ol_error ("  Get track number failed");
    }
    return TRUE;
  }
  else if (status == OL_PLAYER_STOPPED)
  {
    return TRUE;
  }
  else
  {
    ol_errorf ("  unknown status\n");
    return FALSE;
  }
}
Esempio n. 4
0
static gboolean
ol_player_listen_pause ()
{
  ol_logf (OL_DEBUG, "%s\n", __FUNCTION__);
  if (connection == NULL || proxy == NULL)
    if (!ol_player_listen_init_dbus ())
      return FALSE;
  enum OlPlayerStatus status = ol_player_listen_get_status ();
  if (status == OL_PLAYER_ERROR)
    return FALSE;
  if (status == OL_PLAYER_PLAYING)
    return ol_dbus_invoke (proxy, play_pause);
}
Esempio n. 5
0
static enum OlPlayerStatus
ol_player_listen_get_status ()
{
  if (connection == NULL || proxy == NULL)
    if (!ol_player_listen_init_dbus ())
      return OL_PLAYER_ERROR;
  gboolean buf = FALSE;
  enum OlPlayerStatus ret = OL_PLAYER_UNKNOWN;
  if (ol_dbus_get_bool (proxy, get_state, &buf)) 
  {
    ret = ol_player_listen_parse_status (buf);
    //g_free (buf);
  }
  return ret; 
}
Esempio n. 6
0
static gboolean
ol_player_listen_get_activated ()
{
  /* ol_log_func (); */
  if (connection == NULL || proxy == NULL)
    if (!ol_player_listen_init_dbus ())
      return FALSE;
  gchar *buf = NULL;
  if (ol_dbus_get_string (proxy, query, &buf))
  {
    return TRUE;
  }
  else
  {
    return FALSE;
  }
}
Esempio n. 7
0
static gboolean
ol_player_listen_play ()
{
  ol_logf (OL_DEBUG, "%s\n", __FUNCTION__);
  if (connection == NULL || proxy == NULL)
    if (!ol_player_listen_init_dbus ())
      return FALSE;
  enum OlPlayerStatus status = ol_player_listen_get_status ();
  if (status == OL_PLAYER_ERROR)
    return FALSE;
  switch (status)
  {
  case OL_PLAYER_PLAYING:
    return TRUE;
  case OL_PLAYER_STOPPED:
  default:
    return ol_dbus_invoke (proxy, play);
  }
}
Esempio n. 8
0
static gboolean
ol_player_listen_get_played_time (int *played_time)
{
  /* ol_log_func (); */
  int listen_time;
  if (played_time == NULL)
    return FALSE;
  if (connection == NULL || proxy == NULL)
    if (!ol_player_listen_init_dbus ())
      return FALSE;
  enum OlPlayerStatus status = ol_player_listen_get_status ();
  if (status == OL_PLAYER_PLAYING)
  {
    if (!ol_dbus_get_int (proxy, current_position, &listen_time))
      return FALSE;
    listen_time = listen_time*1000;
    if (elapse_emulator == NULL)
    {
      elapse_emulator = g_new (OlElapseEmulator, 1);
      if (elapse_emulator != NULL)
        ol_elapse_emulator_init (elapse_emulator, listen_time, 1000);
    }
    if (elapse_emulator != NULL)
    {
      if (status == OL_PLAYER_PLAYING)
        *played_time = ol_elapse_emulator_get_real_ms (elapse_emulator, listen_time);
      else /* if (status == OL_PLAYER_PAUSED)  */
        *played_time = ol_elapse_emulator_get_last_ms (elapse_emulator, listen_time);
    }
    else
      *played_time = listen_time;
  }
  else
  {
    *played_time = -1;
  }
  return TRUE;
}