diff --git a/app/build.gradle b/app/build.gradle index 3b168514..fb510379 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -70,7 +70,7 @@ android { } dependencies { - implementation 'com.github.SimpleMobileTools:Simple-Commons:f74a128e2e' + implementation 'com.github.SimpleMobileTools:Simple-Commons:ffead928f7' implementation 'org.greenrobot:eventbus:3.3.1' implementation 'androidx.media:media:1.6.0' implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0' diff --git a/app/src/main/kotlin/com/simplemobiletools/musicplayer/services/MusicService.kt b/app/src/main/kotlin/com/simplemobiletools/musicplayer/services/MusicService.kt index a38ffc2d..f747fde0 100644 --- a/app/src/main/kotlin/com/simplemobiletools/musicplayer/services/MusicService.kt +++ b/app/src/main/kotlin/com/simplemobiletools/musicplayer/services/MusicService.kt @@ -30,10 +30,7 @@ import androidx.media.session.MediaButtonReceiver import com.google.gson.Gson import com.google.gson.reflect.TypeToken import com.simplemobiletools.commons.extensions.* -import com.simplemobiletools.commons.helpers.ensureBackgroundThread -import com.simplemobiletools.commons.helpers.isMarshmallowPlus -import com.simplemobiletools.commons.helpers.isOreoPlus -import com.simplemobiletools.commons.helpers.isQPlus +import com.simplemobiletools.commons.helpers.* import com.simplemobiletools.musicplayer.R import com.simplemobiletools.musicplayer.activities.MainActivity import com.simplemobiletools.musicplayer.databases.SongsDatabase @@ -236,7 +233,16 @@ class MusicService : Service(), MediaPlayer.OnPreparedListener, MediaPlayer.OnEr mTracks = getQueuedTracks() val wantedTrackId = intent?.getLongExtra(TRACK_ID, -1L) - mCurrTrack = mTracks.firstOrNull { it.mediaStoreId == wantedTrackId } + + // use an oldschool loop to avoid ConcurrentModificationException + for (i in 0 until mTracks.size) { + val track = mTracks[i] + if (track.mediaStoreId == wantedTrackId) { + mCurrTrack = track + break + } + } + checkTrackOrder() }