From f09693b0becd5af6a32511c5ecc4d8128478752f Mon Sep 17 00:00:00 2001 From: William Wilgus Date: Thu, 26 Sep 2024 03:29:15 -0400 Subject: [Feature/BugFix] Dirplay never gets the file I selected If you have say 1000 playlist entries and select the 1001 song in the directory dirplay loads tracks 1-1000 shuffles them and track 1001 is never heard from again Instead start at the file and loop through the directory mod dir len Change-Id: Ieded5decdc1f7c44b1be8491dbd4f359ae21f79a Hint: this is a good way to not wait on dirplay to load a ton of tracks --- apps/filetree.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'apps') diff --git a/apps/filetree.c b/apps/filetree.c index 6a06fcd5ad..2f4c21dcfe 100644 --- a/apps/filetree.c +++ b/apps/filetree.c @@ -82,7 +82,12 @@ int ft_build_playlist(struct tree_context* c, int start_index) tree_lock_cache(c); struct entry *entries = tree_get_entries(c); - + bool exceeds_pl = false; + if (c->filesindir > playlist->max_playlist_size) + { + exceeds_pl = true; + start_index = 0; + } struct playlist_insert_context pl_context; res = playlist_insert_context_create(playlist, &pl_context, @@ -92,6 +97,9 @@ int ft_build_playlist(struct tree_context* c, int start_index) cpu_boost(true); for(i = 0;i < c->filesindir;i++) { + int item = i; + if (exceeds_pl) + item = (i + start) % c->filesindir; #if 0 /*only needed if displaying progress */ /* user abort */ if (action_userabort(TIMEOUT_NOBLOCK)) @@ -99,13 +107,13 @@ int ft_build_playlist(struct tree_context* c, int start_index) break; } #endif - if((entries[i].attr & FILE_ATTR_MASK) == FILE_ATTR_AUDIO) + if((entries[item].attr & FILE_ATTR_MASK) == FILE_ATTR_AUDIO) { - res = playlist_insert_context_add(&pl_context, entries[i].name); + res = playlist_insert_context_add(&pl_context, entries[item].name); if (res < 0) break; } - else + else if (!exceeds_pl) { /* Adjust the start index when se skip non-MP3 entries */ if(i < start) -- cgit v1.2.3