diff --git a/app/src/main/kotlin/com/simplemobiletools/musicplayer/playback/player/AudioOnlyRenderersFactory.kt b/app/src/main/kotlin/com/simplemobiletools/musicplayer/playback/player/AudioOnlyRenderersFactory.kt index 39d318979..b7e72beea 100644 --- a/app/src/main/kotlin/com/simplemobiletools/musicplayer/playback/player/AudioOnlyRenderersFactory.kt +++ b/app/src/main/kotlin/com/simplemobiletools/musicplayer/playback/player/AudioOnlyRenderersFactory.kt @@ -22,7 +22,7 @@ private const val SKIP_SILENCE_THRESHOLD_LEVEL = 16.toShort() @UnstableApi class AudioOnlyRenderersFactory(context: Context) : DefaultRenderersFactory(context) { - override fun buildAudioSink(context: Context, enableFloatOutput: Boolean, enableAudioTrackPlaybackParams: Boolean): AudioSink { + override fun buildAudioSink(context: Context, enableFloatOutput: Boolean, enableAudioTrackPlaybackParams: Boolean, enableOffload: Boolean): AudioSink? { val silenceSkippingAudioProcessor = SilenceSkippingAudioProcessor( SKIP_SILENCE_MINIMUM_DURATION_US, DEFAULT_PADDING_SILENCE_US, @@ -32,6 +32,13 @@ class AudioOnlyRenderersFactory(context: Context) : DefaultRenderersFactory(cont return DefaultAudioSink.Builder(context) .setEnableFloatOutput(enableFloatOutput) .setEnableAudioTrackPlaybackParams(enableAudioTrackPlaybackParams) + .setOffloadMode( + if (enableOffload) { + DefaultAudioSink.OFFLOAD_MODE_ENABLED_GAPLESS_REQUIRED + } else { + DefaultAudioSink.OFFLOAD_MODE_DISABLED + } + ) .setAudioProcessorChain( DefaultAudioSink.DefaultAudioProcessorChain( arrayOf(), diff --git a/app/src/main/kotlin/com/simplemobiletools/musicplayer/playback/player/Player.kt b/app/src/main/kotlin/com/simplemobiletools/musicplayer/playback/player/Player.kt index c3926424e..165c832cc 100644 --- a/app/src/main/kotlin/com/simplemobiletools/musicplayer/playback/player/Player.kt +++ b/app/src/main/kotlin/com/simplemobiletools/musicplayer/playback/player/Player.kt @@ -64,7 +64,11 @@ private fun PlaybackService.initializePlayer(handleAudioFocus: Boolean, handleAu .build(), handleAudioFocus ) - .setSkipSilenceEnabled(skipSilence) + .setSkipSilenceEnabled( + // TODO: Enable when https://github.com/androidx/media/issues/712 is resolved. + // See https://github.com/SimpleMobileTools/Simple-Music-Player/issues/604 + false //skipSilence + ) .setSeekBackIncrementMs(SEEK_INTERVAL_MS) .setSeekForwardIncrementMs(SEEK_INTERVAL_MS) .setLooper(playerThread.looper) diff --git a/app/src/main/kotlin/com/simplemobiletools/musicplayer/playback/player/SimpleMusicPlayer.kt b/app/src/main/kotlin/com/simplemobiletools/musicplayer/playback/player/SimpleMusicPlayer.kt index 200b279ab..95380440c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/musicplayer/playback/player/SimpleMusicPlayer.kt +++ b/app/src/main/kotlin/com/simplemobiletools/musicplayer/playback/player/SimpleMusicPlayer.kt @@ -141,26 +141,35 @@ class SimpleMusicPlayer(private val exoPlayer: ExoPlayer) : ForwardingPlayer(exo private fun seekWithDelay() { seekJob?.cancel() seekJob = scope.launch { - delay(timeMillis = 400) - if (seekToNextCount > 0 || seekToPreviousCount > 0) { - runOnPlayerThread { - if (currentMediaItem != null) { - if (seekToNextCount > 0) { - seekTo(rotateIndex(currentMediaItemIndex + seekToNextCount), 0) - } - - if (seekToPreviousCount > 0) { - seekTo(rotateIndex(currentMediaItemIndex - seekToPreviousCount), 0) - } - - seekToNextCount = 0 - seekToPreviousCount = 0 - } - } + delay(timeMillis = 300) + val seekCount = seekToNextCount - seekToPreviousCount + if (seekCount != 0) { + seekByCount(seekCount) } } } + private fun seekByCount(seekCount: Int) { + runOnPlayerThread { + if (currentMediaItem == null) { + return@runOnPlayerThread + } + + val currentIndex = currentMediaItemIndex + val seekIndex = if (shuffleModeEnabled) { + val shuffledIndex = shuffledMediaItemsIndices.indexOf(currentIndex) + val seekIndex = rotateIndex(shuffledIndex + seekCount) + shuffledMediaItemsIndices.getOrNull(seekIndex) ?: return@runOnPlayerThread + } else { + rotateIndex(currentIndex + seekCount) + } + + seekTo(seekIndex, 0) + seekToNextCount = 0 + seekToPreviousCount = 0 + } + } + private fun rotateIndex(index: Int): Int { val count = mediaItemCount return (index % count + count) % count diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 8120b98eb..c94ee3de9 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -18,7 +18,7 @@ eventbus = "3.3.1" lottie = "6.1.0" m3uParser = "1.3.0" media = "1.6.0" -media3 = "1.2.0-alpha02" +media3 = "1.1.1" room = "2.5.2" #Simple Mobile Tools simple-commons = "6a7777d740"