playback: remove needless seeking

Remove needless seek calls when setMediaItem will do.
This commit is contained in:
Alexander Capehart 2022-08-28 17:38:03 -06:00
parent 1db5e02332
commit 9fae621f7e
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47
5 changed files with 8 additions and 14 deletions

View file

@ -101,6 +101,7 @@ dependencies {
// WARNING: THE EXOPLAYER VERSION MUST BE KEPT IN LOCK-STEP WITH THE PRE-BUILD SCRIPT.
// IF NOT, VERY UNFRIENDLY BUILD FAILURES AND CRASHES MAY ENSUE.
implementation "com.google.android.exoplayer:exoplayer-core:2.18.1"
implementation fileTree(dir: "libs", include: ["extension-*.aar"])
// Image loading

View file

@ -25,6 +25,7 @@ import com.google.android.material.button.MaterialButton
/**
* A [MaterialButton] that automatically morphs from a circle to a squircle shape appearance when it
* is activated.
* @author OxygenCobalt
*/
class AnimatedMaterialButton
@JvmOverloads

View file

@ -188,14 +188,13 @@ class ReplayGainAudioProcessor(context: Context) : BaseAudioProcessor() {
}
}
private fun parseReplayGainFloat(raw: String): Float {
private fun parseReplayGainFloat(raw: String) =
// Grok a float from a ReplayGain tag by removing everything that is not 0-9, , or -.
return try {
raw.replace(Regex("[^0-9.-]"), "").toFloat()
try {
raw.replace(Regex("[^\\d.-]"), "").toFloat()
} catch (e: Exception) {
0f
}
}
// --- AUDIO PROCESSOR IMPLEMENTATION ---
@ -244,9 +243,8 @@ class ReplayGainAudioProcessor(context: Context) : BaseAudioProcessor() {
// little-endian value.
/** Always get a little-endian short value from a [ByteBuffer] */
private fun ByteBuffer.getLeShort(at: Int): Short {
return get(at + 1).toInt().shl(8).or(get(at).toInt().and(0xFF)).toShort()
}
private fun ByteBuffer.getLeShort(at: Int) =
get(at + 1).toInt().shl(8).or(get(at).toInt().and(0xFF)).toShort()
/** Always place a little-endian short value into a [ByteBuffer]. */
private fun ByteBuffer.putLeShort(short: Short) {

View file

@ -163,7 +163,6 @@ class PlaybackStateManager private constructor() {
}
applyNewQueue(library, settings, settings.keepShuffle && isShuffled, song)
seekTo(0)
notifyNewPlayback()
notifyShuffledChanged()
isPlaying = true
@ -176,7 +175,6 @@ class PlaybackStateManager private constructor() {
val library = musicStore.library ?: return
this.parent = parent
applyNewQueue(library, settings, shuffled, null)
seekTo(0)
notifyNewPlayback()
notifyShuffledChanged()
isPlaying = true
@ -189,7 +187,6 @@ class PlaybackStateManager private constructor() {
val library = musicStore.library ?: return
parent = null
applyNewQueue(library, settings, true, null)
seekTo(0)
notifyNewPlayback()
notifyShuffledChanged()
isPlaying = true
@ -229,7 +226,6 @@ class PlaybackStateManager private constructor() {
private fun gotoImpl(idx: Int, play: Boolean) {
index = idx
seekTo(0)
notifyIndexMoved()
isPlaying = play
}

View file

@ -249,9 +249,7 @@ class PlaybackService :
newPosition: Player.PositionInfo,
reason: Int
) {
if (reason == Player.DISCONTINUITY_REASON_SEEK) {
playbackManager.synchronizePosition(this, player.currentPosition)
}
playbackManager.synchronizePosition(this, player.currentPosition)
}
override fun onTracksChanged(tracks: Tracks) {