Fix repeat mode

This commit is contained in:
daleclack 2023-10-14 14:17:14 +08:00
parent 2fa3042066
commit ed234b9cd1
3 changed files with 31 additions and 0 deletions

View File

@ -272,6 +272,8 @@ static void get_lyrics(gint64 curr_time, gboolean playing, MyMediaPlayer *player
// Get lyrics line
get_lyrics_line(lyrics_content, lyrics_line, FALSE);
g_print("%s\n", lyrics_line);
// Process lyrics line
lyric_line_process(lyrics_line, timestamp_length);
}
@ -430,6 +432,8 @@ static void media_play_ended_handler(MyMediaPlayer *player)
gtk_media_stream_play(stream);
break;
case PlayMode::One_Repeat:
// Reload audio
my_media_player_reload_audio(player);
// Get media stream to control
stream = gtk_video_get_media_stream(GTK_VIDEO(

View File

@ -535,6 +535,31 @@ void my_media_player_load_random_audio(MyMediaPlayer *player)
player->current_audio_index);
}
// Reload audio for repeat mode
void my_media_player_reload_audio(MyMediaPlayer *player)
{
// Clear stream for player
GtkMediaStream *stream = gtk_video_get_media_stream(GTK_VIDEO(player->video));
if (stream != NULL)
{
gtk_media_file_clear(GTK_MEDIA_FILE(stream));
// g_object_unref(stream);
}
// Clear video widget
gtk_video_set_file(GTK_VIDEO(player->video), NULL);
// Load music at index
// Get item
MyItem *item = MY_ITEM(g_list_model_get_item(G_LIST_MODEL(player->music_store),
player->current_audio_index));
load_audio(item, player);
// Update selected item
gtk_single_selection_set_selected(player->music_selection,
player->current_audio_index);
}
// Stop current music
static void btnstop_clicked(GtkButton *self, MyMediaPlayer *player)
{

View File

@ -32,4 +32,6 @@ void btnnext_clicked(GtkButton *self, MyMediaPlayer *player);
void my_media_player_load_random_audio(MyMediaPlayer *player);
void my_media_player_reload_audio(MyMediaPlayer *player);
MyMediaPlayer *my_media_player_new(GtkApplication *app);