fix: avoid duplicate playback events at the end of the timeline
Also prefer the freshest mood detail during offline sync and reset the skip suppression after a previous that only restarted the track.
This commit is contained in:
1 parent
1e3dac4e47
commit
8cf77f156d
2 files changed
+21
-7
No files matched your search
@@ -1161,7 +1161,11 @@ class AppStore(
|
||||
_state.update {
|
||||
it.copy(
|
||||
downloads = storage.listDownloads().keys,
|
||||
message = "Download removed",
|
||||
message = if (settings.offlineMoods.isEmpty()) {
|
||||
"Download removed"
|
||||
} else {
|
||||
"Download removed; offline moods restore it on the next sync"
|
||||
},
|
||||
messageIsError = false,
|
||||
messageId = it.messageId + 1,
|
||||
)
|
||||
@@ -1258,7 +1262,7 @@ class AppStore(
|
||||
private fun syncOfflineMoods() {
|
||||
if (settings.offlineMoods.isEmpty()) return
|
||||
if (!isUnmeteredNetwork()) return
|
||||
val details = (cache.load().moodDetails + listOfNotNull(_state.value.selectedMood))
|
||||
val details = (listOfNotNull(_state.value.selectedMood) + cache.load().moodDetails)
|
||||
.distinctBy { it.mood.id }
|
||||
val songs = details
|
||||
.filter { it.mood.id in settings.offlineMoods }
|
||||
@@ -1380,6 +1384,10 @@ class AppStore(
|
||||
suppressCompletion = false
|
||||
trackIndex = index
|
||||
report("started", timelineSongs.getOrNull(index)?.id, 0)
|
||||
} else {
|
||||
// A previous that restarted the track must not suppress the next
|
||||
// natural completion event.
|
||||
suppressCompletion = false
|
||||
}
|
||||
applyTimelineState()
|
||||
_state.update {
|
||||
@@ -1503,16 +1511,18 @@ class AppStore(
|
||||
|
||||
/** Returns false when playback should stop at the end of the timeline. */
|
||||
private suspend fun advanceAtEnd(): Boolean {
|
||||
if (fetching) {
|
||||
delay(500)
|
||||
return true
|
||||
}
|
||||
// A prefetch may already have appended the next batch while ExoPlayer
|
||||
// was finishing. Play it instead of requesting duplicates.
|
||||
if (trackIndex + 1 < timelineSongs.size) {
|
||||
report("completed", timelineSongs.getOrNull(trackIndex)?.id, _state.value.positionSeconds.toInt())
|
||||
suppressCompletion = true
|
||||
player.playIndex(trackIndex + 1)
|
||||
return true
|
||||
}
|
||||
if (fetching) {
|
||||
delay(500)
|
||||
return true
|
||||
}
|
||||
if (_state.value.sleepAtTrackEnd) {
|
||||
sleepJob?.cancel()
|
||||
sleepJob = null
|
||||
@@ -1530,6 +1540,7 @@ class AppStore(
|
||||
val session = _state.value.session
|
||||
val current = timelineSongs.getOrNull(trackIndex)
|
||||
if (session == null) {
|
||||
report("completed", timelineSongs.getOrNull(trackIndex)?.id, _state.value.positionSeconds.toInt())
|
||||
_state.update { it.copy(playing = false) }
|
||||
return false
|
||||
}
|
||||
@@ -1539,6 +1550,7 @@ class AppStore(
|
||||
return false
|
||||
}
|
||||
if (more.isEmpty()) {
|
||||
report("completed", timelineSongs.getOrNull(trackIndex)?.id, _state.value.positionSeconds.toInt())
|
||||
_state.update { it.copy(playing = false) }
|
||||
return false
|
||||
}
|
||||
@@ -1546,6 +1558,8 @@ class AppStore(
|
||||
val from = timelineSongs.size
|
||||
timelineSongs = timelineSongs + more
|
||||
player.appendToQueue(buildTracks(more))
|
||||
report("completed", timelineSongs.getOrNull(trackIndex)?.id, _state.value.positionSeconds.toInt())
|
||||
suppressCompletion = true
|
||||
applyTimelineState()
|
||||
_state.update { it.copy(playing = true) }
|
||||
player.playIndex(from)
|
||||
|
||||
@@ -142,7 +142,7 @@ fun PlayerBar(state: AppState, store: AppStore) {
|
||||
Icon(
|
||||
Icons.Rounded.Bedtime,
|
||||
contentDescription = "Sleep timer",
|
||||
tint = if (sleepRemaining != null) {
|
||||
tint = if (sleepRemaining != null || state.sleepAtTrackEnd) {
|
||||
MaterialTheme.colorScheme.primary
|
||||
} else {
|
||||
MaterialTheme.colorScheme.onSurfaceVariant
|
||||
|
||||
Reference in new issue
Block a user