diff --git a/app/src/main/kotlin/com/simplemobiletools/musicplayer/activities/SettingsActivity.kt b/app/src/main/kotlin/com/simplemobiletools/musicplayer/activities/SettingsActivity.kt index e9a48fc9..49ac0143 100644 --- a/app/src/main/kotlin/com/simplemobiletools/musicplayer/activities/SettingsActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/musicplayer/activities/SettingsActivity.kt @@ -152,7 +152,7 @@ class SettingsActivity : SimpleControllerActivity() { settings_gapless_playback.toggle() config.gaplessPlayback = settings_gapless_playback.isChecked withPlayer { - TODO("Toggle skip silence.") + sendCommand(CustomCommands.TOGGLE_SKIP_SILENCE) } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/musicplayer/playback/CustomCommands.kt b/app/src/main/kotlin/com/simplemobiletools/musicplayer/playback/CustomCommands.kt index cfc08796..240872bd 100644 --- a/app/src/main/kotlin/com/simplemobiletools/musicplayer/playback/CustomCommands.kt +++ b/app/src/main/kotlin/com/simplemobiletools/musicplayer/playback/CustomCommands.kt @@ -14,7 +14,8 @@ enum class CustomCommands(val customAction: String) { CLOSE_PLAYER(customAction = PATH + "CLOSE_PLAYER"), RELOAD_CONTENT(customAction = PATH + "RELOAD_CONTENT"), SAVE_QUEUE(customAction = PATH + "SAVE_QUEUE"), - TOGGLE_SLEEP_TIMER(customAction = PATH + "TOGGLE_SLEEP_TIMER"); + TOGGLE_SLEEP_TIMER(customAction = PATH + "TOGGLE_SLEEP_TIMER"), + TOGGLE_SKIP_SILENCE(customAction = PATH + "TOGGLE_SKIP_SILENCE"); val sessionCommand = SessionCommand(customAction, Bundle.EMPTY) diff --git a/app/src/main/kotlin/com/simplemobiletools/musicplayer/playback/MediaSessionCallback.kt b/app/src/main/kotlin/com/simplemobiletools/musicplayer/playback/MediaSessionCallback.kt index 5849b4ad..9e28e38b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/musicplayer/playback/MediaSessionCallback.kt +++ b/app/src/main/kotlin/com/simplemobiletools/musicplayer/playback/MediaSessionCallback.kt @@ -10,6 +10,7 @@ import androidx.media3.session.MediaLibraryService.MediaLibrarySession import com.google.common.util.concurrent.Futures import com.google.common.util.concurrent.ListenableFuture import com.google.common.util.concurrent.MoreExecutors +import com.simplemobiletools.musicplayer.extensions.config import com.simplemobiletools.musicplayer.extensions.currentMediaItems import java.util.concurrent.Executors @@ -68,6 +69,7 @@ internal fun PlaybackService.getMediaSessionCallback() = object : MediaLibrarySe CustomCommands.RELOAD_CONTENT -> reloadContent() CustomCommands.SAVE_QUEUE -> saveRecentItems() CustomCommands.TOGGLE_SLEEP_TIMER -> toggleSleepTimer() + CustomCommands.TOGGLE_SKIP_SILENCE -> player.setSkipSilence(config.gaplessPlayback) } return Futures.immediateFuture(SessionResult(SessionResult.RESULT_SUCCESS)) 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 3f3b51a1..6540bcb7 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 @@ -28,4 +28,8 @@ class SimpleMusicPlayer(val exoPlayer: ExoPlayer) : ForwardingPlayer(exoPlayer) override fun play() { playWhenReady = true } + + fun setSkipSilence(skipSilence: Boolean) { + exoPlayer.skipSilenceEnabled = skipSilence + } }