From 6e08731835172bc68f40eba1ceedca8f5db1ac38 Mon Sep 17 00:00:00 2001 From: William Wilgus Date: Sat, 14 Jan 2023 00:34:36 -0500 Subject: [Feature] onplay.c Playlist Playing Time more fault tolerant bad tracks now get skipped with a message at the end of scanning rather than an error killing the count Change-Id: I6d8c14ce00e78416b772bc5e9093a889351bc3de --- apps/onplay.c | 57 +++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 39 insertions(+), 18 deletions(-) diff --git a/apps/onplay.c b/apps/onplay.c index 2504835f77..56809e45cd 100644 --- a/apps/onplay.c +++ b/apps/onplay.c @@ -367,11 +367,13 @@ static int playing_time_speak_info(int selected_item, void * data) other stats */ static bool playing_time(void) { + int error_count = 0; unsigned long talked_tick = current_tick; struct playing_time_info pti; struct playlist_track_info pltrack; struct mp3entry id3; - int i, fd, ret; + int i, fd; + bool ret; pti.nb_tracks = playlist_amount(); playlist_get_resume_info(&pti.curr_playing); @@ -407,24 +409,44 @@ static bool playing_time(void) if (i == pti.curr_playing) continue; - if (playlist_get_track_info(NULL, i, &pltrack) < 0) - goto error; - if ((fd = open(pltrack.filename, O_RDONLY)) < 0) - goto error; - ret = get_metadata(&id3, fd, pltrack.filename); - close(fd); - if (!ret) - goto error; - - if (i < pti.curr_playing) { - pti.secs_bef += id3.length/1000; - pti.kbs_bef += id3.filesize/1024; - } else { - pti.secs_aft += id3.length/1000; - pti.kbs_aft += id3.filesize/1024; + if (playlist_get_track_info(NULL, i, &pltrack) >= 0) + { + ret = false; + if ((fd = open(pltrack.filename, O_RDONLY)) >= 0) + { + ret = get_metadata(&id3, fd, pltrack.filename); + close(fd); + if (ret) + { + if (i < pti.curr_playing) { + pti.secs_bef += id3.length/1000; + pti.kbs_bef += id3.filesize/1024; + } else { + pti.secs_aft += id3.length/1000; + pti.kbs_aft += id3.filesize/1024; + } + } + } + + if (!ret) + { + error_count++; + continue; + } + } + else + { + error_count++; + break; } } + if (error_count > 0) + { + splash(HZ, ID2P(LANG_PLAYTIME_ERROR)); + } + + pti.nb_tracks -= error_count; pti.secs_ttl = pti.secs_bef +pti.secs_aft; pti.trk_secs_ttl = pti.trk_secs_bef +pti.trk_secs_aft; pti.kbs_ttl = pti.kbs_bef +pti.kbs_aft; @@ -447,8 +469,7 @@ static bool playing_time(void) return(default_event_handler(key) == SYS_USB_CONNECTED); } } - error: - splash(HZ, ID2P(LANG_PLAYTIME_ERROR)); + exit: return false; } -- cgit v1.2.3