Fix lyrics update
This commit is contained in:
parent
05a4c31e60
commit
8f9a1ae12e
|
@ -96,14 +96,6 @@ void update_lyrics(MyMediaPlayer *player)
|
||||||
strncat(lyric_filename, ".lrc", 4);
|
strncat(lyric_filename, ".lrc", 4);
|
||||||
g_print("%s\n", lyric_filename);
|
g_print("%s\n", lyric_filename);
|
||||||
|
|
||||||
// Close pervious opened lyrics file
|
|
||||||
if (lyrics_file != NULL)
|
|
||||||
{
|
|
||||||
fclose(lyrics_file);
|
|
||||||
lyrics_file = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Open the lyrics file
|
|
||||||
lyrics_file = fopen(lyric_filename, "rt+");
|
lyrics_file = fopen(lyric_filename, "rt+");
|
||||||
lyrics_updated = TRUE;
|
lyrics_updated = TRUE;
|
||||||
line_read = FALSE;
|
line_read = FALSE;
|
||||||
|
@ -125,7 +117,7 @@ static void get_lyrics(gint64 curr_time, gboolean playing, MyMediaPlayer *player
|
||||||
{
|
{
|
||||||
// Get lyrics time
|
// Get lyrics time
|
||||||
fgets(lyrics_line, lyrics_max_length, lyrics_file);
|
fgets(lyrics_line, lyrics_max_length, lyrics_file);
|
||||||
fflush(lyrics_file);
|
// fflush(lyrics_file);
|
||||||
|
|
||||||
// Some lrc files has empty lines
|
// Some lrc files has empty lines
|
||||||
if (strlen(lyrics_line) == 0)
|
if (strlen(lyrics_line) == 0)
|
||||||
|
@ -154,6 +146,8 @@ static void get_lyrics(gint64 curr_time, gboolean playing, MyMediaPlayer *player
|
||||||
}
|
}
|
||||||
// g_print("%ld\n", lyric_time);
|
// g_print("%ld\n", lyric_time);
|
||||||
|
|
||||||
|
// g_print("%lld %lld\n", curr_time, lyric_time);
|
||||||
|
// g_print("%d\n", line_read);
|
||||||
if (curr_time / 100 == lyric_time / 100 && line_read || lyric_time == 0)
|
if (curr_time / 100 == lyric_time / 100 && line_read || lyric_time == 0)
|
||||||
{
|
{
|
||||||
// Since a new line is read and time match, load lyrics
|
// Since a new line is read and time match, load lyrics
|
||||||
|
@ -166,6 +160,7 @@ static void get_lyrics(gint64 curr_time, gboolean playing, MyMediaPlayer *player
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
// g_print("Lyric file open failed!\n");
|
||||||
gtk_label_set_markup(my_media_player_get_lyrics_widget(player),
|
gtk_label_set_markup(my_media_player_get_lyrics_widget(player),
|
||||||
"<span color=\"red\" size='12pt'>No Lyric File Found!</span>");
|
"<span color=\"red\" size='12pt'>No Lyric File Found!</span>");
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ struct _MyMediaPlayer
|
||||||
GtkWidget *btn_add, *btn_remove;
|
GtkWidget *btn_add, *btn_remove;
|
||||||
GtkWidget *btn_load, *btn_save;
|
GtkWidget *btn_load, *btn_save;
|
||||||
GtkWidget *column_view;
|
GtkWidget *column_view;
|
||||||
GtkWidget *scrolled_window;
|
GtkWidget *scrolled_window, *scrolled_lyrics;
|
||||||
GListStore *music_store;
|
GListStore *music_store;
|
||||||
char current_filename[path_max_length];
|
char current_filename[path_max_length];
|
||||||
gboolean music_loaded;
|
gboolean music_loaded;
|
||||||
|
@ -169,12 +169,15 @@ static void my_media_player_init(MyMediaPlayer *self)
|
||||||
self->btn_box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 5);
|
self->btn_box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 5);
|
||||||
self->btn_add = gtk_button_new_from_icon_name("list-add");
|
self->btn_add = gtk_button_new_from_icon_name("list-add");
|
||||||
self->scrolled_window = gtk_scrolled_window_new();
|
self->scrolled_window = gtk_scrolled_window_new();
|
||||||
|
self->scrolled_lyrics = gtk_scrolled_window_new();
|
||||||
self->btn_remove = gtk_button_new_from_icon_name("list-remove");
|
self->btn_remove = gtk_button_new_from_icon_name("list-remove");
|
||||||
self->btn_load = gtk_button_new_from_icon_name("go-up");
|
self->btn_load = gtk_button_new_from_icon_name("go-up");
|
||||||
self->btn_save = gtk_button_new_from_icon_name("document-save");
|
self->btn_save = gtk_button_new_from_icon_name("document-save");
|
||||||
gtk_widget_set_size_request(self->video, 300, 150);
|
gtk_widget_set_size_request(self->video, 300, 150);
|
||||||
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(self->scrolled_window),
|
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(self->scrolled_window),
|
||||||
GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
|
GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
|
||||||
|
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(self->scrolled_window),
|
||||||
|
GTK_POLICY_AUTOMATIC, GTK_POLICY_NEVER);
|
||||||
gtk_label_set_markup(GTK_LABEL(self->label_lyrics),
|
gtk_label_set_markup(GTK_LABEL(self->label_lyrics),
|
||||||
"<span color=\"red\" size='12pt'>No Lyric File Found!</span>");
|
"<span color=\"red\" size='12pt'>No Lyric File Found!</span>");
|
||||||
|
|
||||||
|
@ -208,7 +211,9 @@ static void my_media_player_init(MyMediaPlayer *self)
|
||||||
|
|
||||||
// Add widgets
|
// Add widgets
|
||||||
gtk_box_append(GTK_BOX(self->main_box), self->video);
|
gtk_box_append(GTK_BOX(self->main_box), self->video);
|
||||||
gtk_box_append(GTK_BOX(self->main_box), self->label_lyrics);
|
gtk_scrolled_window_set_child(GTK_SCROLLED_WINDOW(self->scrolled_lyrics),
|
||||||
|
self->label_lyrics);
|
||||||
|
gtk_box_append(GTK_BOX(self->main_box), self->scrolled_lyrics);
|
||||||
gtk_box_append(GTK_BOX(self->btn_box), self->btn_add);
|
gtk_box_append(GTK_BOX(self->btn_box), self->btn_add);
|
||||||
gtk_box_append(GTK_BOX(self->btn_box), self->btn_remove);
|
gtk_box_append(GTK_BOX(self->btn_box), self->btn_remove);
|
||||||
gtk_box_append(GTK_BOX(self->btn_box), self->btn_load);
|
gtk_box_append(GTK_BOX(self->btn_box), self->btn_load);
|
||||||
|
|
Loading…
Reference in New Issue