Fixes a crash during playback (#1514)

## Description
Fixes a crash that could occur during the beginning of playback

Also adds better handling for clicking next extremely fast

### Technical details

The playlist objects would be created on the IO thread and it had a
`mutableIntStateOf` to track the current index. This meant that there is
a race conditions for the IO thread to commit the snapshot for the main
thread to see them. If the main thread is faster, it will crash.

To fix that, this PR moves the mutable state in `Playlist` into the
`PlaybackState` flow in the view model. This enures both the background
threads and re-compositions have the right state.

### Related issues
Fixes #1509 

### Testing
Emulator

## Screenshots
N/A

## AI or LLM usage
None
This commit is contained in:
Damontecres 2026-06-03 12:41:13 -04:00 • committed by GitHub
parent 5ae452155e
commit 471dbd62db
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 99 additions and 89 deletions

View file

@ -78,7 +78,7 @@ class PlaylistCreator
.convertAndAddParts(false)
val startIndex =
episodeId?.let { episodes.indexOfFirstOrNull { it.id == episodeId } } ?: 0
return Playlist(episodes, startIndex)
return Playlist(episodes.subList(startIndex, episodes.size))
}
/**
@ -104,7 +104,7 @@ class PlaylistCreator
),
)
val items = GetItemsRequestHandler.execute(api, request).content.items
return Playlist(items.convertAndAddParts(), 0)
return Playlist(items.convertAndAddParts())
}
private suspend fun createFromCollection(
@ -147,7 +147,7 @@ class PlaylistCreator
.execute(api, request)
.content.items
.convertAndAddParts()
return Playlist(items, 0)
return Playlist(items)
}
/**
@ -263,7 +263,7 @@ class PlaylistCreator
}.let(::addAll)
}
}
PlaylistCreationResult.Success(Playlist(list, 0))
PlaylistCreationResult.Success(Playlist(list))
}
// Not support yet