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. // 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. // IF NOT, VERY UNFRIENDLY BUILD FAILURES AND CRASHES MAY ENSUE.
implementation "com.google.android.exoplayer:exoplayer-core:2.18.1" implementation "com.google.android.exoplayer:exoplayer-core:2.18.1"
implementation fileTree(dir: "libs", include: ["extension-*.aar"]) implementation fileTree(dir: "libs", include: ["extension-*.aar"])
// Image loading // 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 * A [MaterialButton] that automatically morphs from a circle to a squircle shape appearance when it
* is activated. * is activated.
* @author OxygenCobalt
*/ */
class AnimatedMaterialButton class AnimatedMaterialButton
@JvmOverloads @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 -. // Grok a float from a ReplayGain tag by removing everything that is not 0-9, , or -.
return try { try {
raw.replace(Regex("[^0-9.-]"), "").toFloat() raw.replace(Regex("[^\\d.-]"), "").toFloat()
} catch (e: Exception) { } catch (e: Exception) {
0f 0f
} }
}
// --- AUDIO PROCESSOR IMPLEMENTATION --- // --- AUDIO PROCESSOR IMPLEMENTATION ---
@ -244,9 +243,8 @@ class ReplayGainAudioProcessor(context: Context) : BaseAudioProcessor() {
// little-endian value. // little-endian value.
/** Always get a little-endian short value from a [ByteBuffer] */ /** Always get a little-endian short value from a [ByteBuffer] */
private fun ByteBuffer.getLeShort(at: Int): Short { private fun ByteBuffer.getLeShort(at: Int) =
return get(at + 1).toInt().shl(8).or(get(at).toInt().and(0xFF)).toShort() get(at + 1).toInt().shl(8).or(get(at).toInt().and(0xFF)).toShort()
}
/** Always place a little-endian short value into a [ByteBuffer]. */ /** Always place a little-endian short value into a [ByteBuffer]. */
private fun ByteBuffer.putLeShort(short: Short) { private fun ByteBuffer.putLeShort(short: Short) {

View file

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

View file

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