behavior: add option to pause when a song repeats

Add a new option to pause playback whenever a song loops [e.g while in
LoopMode.TRACK]. This does mean that we can no longer use exoplayer's
native looping system, but it doesn't seem to be that much of an issue.

Resolves #29.
This commit is contained in:
OxygenCobalt
2021-07-22 17:00:51 -06:00
parent 33332dbf6b
commit 2e278aef8a
5 changed files with 29 additions and 11 deletions
@@ -160,7 +160,7 @@ class PlaybackNotification private constructor(
iconRes, actionName,
PendingIntent.getBroadcast(
context, REQUEST_CODE,
Intent(actionName), PendingIntent.FLAG_UPDATE_CURRENT
Intent(actionName), PendingIntent.FLAG_UPDATE_CURRENT,
)
)
@@ -188,7 +188,17 @@ class PlaybackService : Service(), Player.Listener, PlaybackStateManager.Callbac
releaseWakelock()
}
Player.STATE_ENDED -> playbackManager.next()
Player.STATE_ENDED -> {
if (playbackManager.loopMode == LoopMode.TRACK) {
playbackManager.rewind()
if (settingsManager.pauseOnLoop) {
playbackManager.setPlaying(false)
}
} else {
playbackManager.next()
}
}
else -> {}
}
@@ -249,12 +259,6 @@ class PlaybackService : Service(), Player.Listener, PlaybackStateManager.Callbac
}
override fun onLoopUpdate(loopMode: LoopMode) {
player.repeatMode = if (loopMode == LoopMode.TRACK) {
Player.REPEAT_MODE_ONE
} else {
Player.REPEAT_MODE_OFF
}
if (!settingsManager.useAltNotifAction) {
notification.setLoop(this, loopMode)
@@ -97,6 +97,10 @@ class SettingsManager private constructor(context: Context) :
val rewindWithPrev: Boolean
get() = sharedPrefs.getBoolean(KEY_PREV_REWIND, true)
/** Whether [LoopMode.TRACK] should pause when the track repeats */
val pauseOnLoop: Boolean
get() = sharedPrefs.getBoolean(KEY_LOOP_PAUSE, false)
/** The current [SortMode] of the library. */
var librarySortMode: SortMode
get() = sharedPrefs.getData(KEY_LIB_SORT_MODE, SortMode::fromInt) ?: SortMode.ALPHA_DOWN
@@ -214,6 +218,7 @@ class SettingsManager private constructor(context: Context) :
const val KEY_SONG_PLAYBACK_MODE = "KEY_SONG_PLAY_MODE2"
const val KEY_KEEP_SHUFFLE = "KEY_KEEP_SHUFFLE"
const val KEY_PREV_REWIND = "KEY_PREV_REWIND"
const val KEY_LOOP_PAUSE = "KEY_LOOP_PAUSE"
const val KEY_SAVE_STATE = "KEY_SAVE_STATE"
const val KEY_BLACKLIST = "KEY_BLACKLIST"