From b5b8767f4621644098b6dd9528d9bb86822446e0 Mon Sep 17 00:00:00 2001 From: OxygenCobalt Date: Sun, 6 Mar 2022 19:25:48 -0700 Subject: [PATCH] playback: fix crash with state restore [#89] Fix an esoteric crash with queue synchronization during the playback restore process. Auxio will attempt to re-synchronize the queue index whenever it is desynchronized, however during the check for if it's desynchronized, Auxio would do a direct index of the queue, which could result in a crash in situations where the desynchronized index is outside of the queue bounds. Fix this by replacing that unprotected access with a protected access, which not only fixes the crash but also still correctly detects desynchronization in that case. Resolves #89. --- CHANGELOG.md | 2 +- .../oxycblt/auxio/playback/state/PlaybackStateManager.kt | 6 +++++- info/ADDITIONS.md | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3708c39a2..090ed95e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,6 @@ # Changelog ## dev [v2.2.2 or 2.3.0] - #### What's New - New spanish translations and metadata [courtesy of n-berenice] @@ -16,6 +15,7 @@ from the system theme was used [#80] - Fixed incorrect track numbers when the tag was formatted as NN/TT [#88] - Fixed years deliberately set as "0" showing up as "No Date" - Fixed headset management unexpectedly starting audio when the app initially opens +- Fixed crash that would occur during a playback restore with specific queue states [#89] #### What's Changed - All cover art is now cropped to a 1:1 aspect ratio diff --git a/app/src/main/java/org/oxycblt/auxio/playback/state/PlaybackStateManager.kt b/app/src/main/java/org/oxycblt/auxio/playback/state/PlaybackStateManager.kt index 45bb3b1fc..5f2d81a29 100644 --- a/app/src/main/java/org/oxycblt/auxio/playback/state/PlaybackStateManager.kt +++ b/app/src/main/java/org/oxycblt/auxio/playback/state/PlaybackStateManager.kt @@ -40,6 +40,8 @@ import org.oxycblt.auxio.util.logE * * All access should be done with [PlaybackStateManager.getInstance]. * @author OxygenCobalt + * + * TODO: Rework this to possibly handle gapless playback and more refined queue management. */ class PlaybackStateManager private constructor() { // Playback @@ -594,7 +596,9 @@ class PlaybackStateManager private constructor() { * Do a sanity check to make sure that the index lines up with the current song. */ private fun doIndexSanityCheck() { - if (mSong != null && mSong != mQueue[mIndex]) { + // Note: Be careful with how we handle the queue since a possible index desync + // could easily result in an OOB issue. + if (mSong != null && mSong != mQueue.getOrNull(mIndex)) { val correctedIndex = mQueue.wobblyIndexOfFirst(mIndex, mSong) if (correctedIndex > -1) { diff --git a/info/ADDITIONS.md b/info/ADDITIONS.md index 68b127a22..f0474d5d5 100644 --- a/info/ADDITIONS.md +++ b/info/ADDITIONS.md @@ -9,7 +9,6 @@ While I do like adding new behavior/UI customizations, these will be looked at m ## Feature Additions and UI Changes These arent as likely to be accepted. As I said, I do not want Auxio to become overly bloated with features that are rarely used, therefore I only tend to accept features that: - - Benefit **my own** usage - Are in line with Auxio's purpose as a music player @@ -25,3 +24,4 @@ Feel free to fork Auxio to add your own feature set however. - Gapless Playback [#35] (Technical issues, may change in the future) - Reduce leading instrument [#45] (Technical issues, Out of scope) - Opening music through a provider [#30] (Out of scope) +- Cuesheet support [#83]