File tree Expand file tree Collapse file tree 1 file changed +24
-15
lines changed
app/src/main/kotlin/com/simplemobiletools/musicplayer/playback/player Expand file tree Collapse file tree 1 file changed +24
-15
lines changed Original file line number Diff line number Diff line change @@ -142,25 +142,34 @@ class SimpleMusicPlayer(private val exoPlayer: ExoPlayer) : ForwardingPlayer(exo
142142 seekJob?.cancel()
143143 seekJob = scope.launch {
144144 delay(timeMillis = 400 )
145- if (seekToNextCount > 0 || seekToPreviousCount > 0 ) {
146- runOnPlayerThread {
147- if (currentMediaItem != null ) {
148- if (seekToNextCount > 0 ) {
149- seekTo(rotateIndex(currentMediaItemIndex + seekToNextCount), 0 )
150- }
151-
152- if (seekToPreviousCount > 0 ) {
153- seekTo(rotateIndex(currentMediaItemIndex - seekToPreviousCount), 0 )
154- }
155-
156- seekToNextCount = 0
157- seekToPreviousCount = 0
158- }
159- }
145+ val seekCount = seekToNextCount - seekToPreviousCount
146+ if (seekCount != 0 ) {
147+ seekByCount(seekCount)
160148 }
161149 }
162150 }
163151
152+ private fun seekByCount (seekCount : Int ) {
153+ runOnPlayerThread {
154+ if (currentMediaItem == null ) {
155+ return @runOnPlayerThread
156+ }
157+
158+ val currentIndex = currentMediaItemIndex
159+ val seekIndex = if (shuffleModeEnabled) {
160+ val shuffledIndex = shuffledMediaItemsIndices.indexOf(currentIndex)
161+ val seekIndex = rotateIndex(shuffledIndex + seekCount)
162+ shuffledMediaItemsIndices.getOrNull(seekIndex) ? : return @runOnPlayerThread
163+ } else {
164+ rotateIndex(currentIndex + seekCount)
165+ }
166+
167+ seekTo(seekIndex, 0 )
168+ seekToNextCount = 0
169+ seekToPreviousCount = 0
170+ }
171+ }
172+
164173 private fun rotateIndex (index : Int ): Int {
165174 val count = mediaItemCount
166175 return (index % count + count) % count
You can’t perform that action at this time.
0 commit comments