From b858a4803252380e1d378a5712a3e810f45f2891 Mon Sep 17 00:00:00 2001 From: Christopher Snowhill Date: Tue, 11 Feb 2025 23:04:01 -0800 Subject: [PATCH] Bug Fix: Fix resume playback on startup In case multiple playlist entries are left marked as "current" in the playlist database, resume playback on the first one, and unmark all the rest of them. Signed-off-by: Christopher Snowhill --- Application/AppController.m | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Application/AppController.m b/Application/AppController.m index 412597ff1..033c3c32e 100644 --- a/Application/AppController.m +++ b/Application/AppController.m @@ -249,7 +249,7 @@ static AppController *kAppController = nil; NSError *error = nil; NSArray *results = [playlistController.persistentContainer.viewContext executeFetchRequest:request error:&error]; - if(results && [results count] == 1) { + if(results && [results count] > 0) { PlaylistEntry *pe = results[0]; if([[NSUserDefaults standardUserDefaults] boolForKey:@"resumePlaybackOnStartup"]) { [playbackController playEntryAtIndex:pe.index startPaused:(lastStatus == CogStatusPaused) andSeekTo:@(pe.currentPosition)]; @@ -260,6 +260,13 @@ static AppController *kAppController = nil; pe.countAdded = NO; [playlistController commitPersistentStore]; } + // Bug fix + if([results count] > 1) { + for(size_t i = 1; i < [results count]; ++i) { + PlaylistEntry *pe = results[i]; + [pe setCurrent:NO]; + } + } } }