static void _seek_cb (OlScrollWindow *scroll, guint id, gdouble percentage, gpointer userdata) { OlScrollModule *module = userdata; if (module->lrc) { OlLrcIter *iter = ol_lrc_iter_from_id (module->lrc, id); if (!ol_lrc_iter_is_valid (iter)) { ol_errorf ("Seek to an invalid ID: %u\n", id); ol_lrc_iter_free (iter); return; } gint64 iter_time = ol_lrc_iter_get_timestamp (iter); guint64 duration = ol_lrc_iter_get_duration (iter); ol_lrc_iter_free (iter); gint64 new_time = iter_time + duration * percentage; ol_player_seek (module->player, new_time); ol_scroll_window_set_progress (module->scroll, id, percentage); /* avoid players send played time before seeked. */ g_usleep (200000); } }
void ol_scroll_module_set_lrc (struct OlDisplayModule *module, OlLrc *lrc) { ol_log_func (); ol_assert (module != NULL); ol_assert (module != NULL); OlScrollModule *priv = ol_display_module_get_data (module); ol_assert (priv != NULL); if (priv->lrc != NULL) g_object_unref (priv->lrc); priv->lrc = lrc; if (priv->lrc == NULL) ol_scroll_window_set_whole_lyrics(priv->scroll, NULL); else { g_object_ref (priv->lrc); /*dump the whole lyrics of a song*/ GPtrArray *text_array = g_ptr_array_new_with_free_func (g_free); OlLrcIter *iter = ol_lrc_iter_from_id (lrc, 0); const char *text = NULL; while (ol_lrc_iter_loop (iter, NULL, NULL, &text)) { g_ptr_array_add (text_array, g_strdup (text)); } ol_scroll_window_set_whole_lyrics(priv->scroll, text_array); g_ptr_array_unref (text_array); ol_lrc_iter_free (iter); } }
static void ol_osd_module_set_played_time (struct OlDisplayModule *module, guint64 played_time) { ol_assert (module != NULL); OlOsdModule *priv = ol_display_module_get_data (module); ol_assert (priv != NULL); if (priv->lrc != NULL && priv->window != NULL) { OlLrcIter *iter = ol_lrc_iter_from_timestamp (priv->lrc, played_time); if (_advance_to_nonempty_lyric (iter)) { gint id = ol_lrc_iter_get_id (iter); if (id != priv->lrc_id) { if (id == priv->lrc_next_id) { /* advance to the next line */ ol_osd_window_set_percentage (priv->window, priv->current_line, 1.0); priv->current_line = 1 - priv->current_line; priv->lrc_id = priv->lrc_next_id; priv->lrc_next_id = -1; ol_osd_window_set_current_line (priv->window, priv->current_line); } else { /* The user seeks the position or there is only 1 line in OSD window. Reset the lyrics. */ priv->lrc_id = id; priv->current_line = 0; ol_osd_window_set_current_line (priv->window, 0); ol_osd_window_set_lyric (priv->window, priv->current_line, ol_lrc_iter_get_text (iter)); ol_osd_module_update_next_lyric (priv, iter); } } gdouble percentage = ol_lrc_iter_compute_percentage (iter, played_time); ol_osd_window_set_current_percentage (priv->window, percentage); if (percentage > 0.5 && priv->lrc_next_id == -1) ol_osd_module_update_next_lyric (priv, iter); } else if (priv->lrc_id != -1) { clear_lyrics (priv); } ol_lrc_iter_free (iter); } }
static void ol_scroll_module_set_played_time (struct OlDisplayModule *module, guint64 played_time) { ol_assert (module != NULL); OlScrollModule *priv = ol_display_module_get_data (module); ol_assert (priv != NULL); if (priv->lrc != NULL && priv->scroll != NULL) { OlLrcIter *iter = ol_lrc_iter_from_timestamp (priv->lrc, played_time); ol_scroll_window_set_progress (priv->scroll, ol_lrc_iter_get_id (iter), ol_lrc_iter_compute_percentage (iter, played_time)); ol_lrc_iter_free (iter); } }