playback: fix queue adding with one-song queues
Fix an issue where with queues of one-song, adding another song with "Play next" results in it going behind the current song. This stemmed from a fix for a crash with empty queues, so instead of doing some insane min/max logic we just check if the queue is empty and just don't add the item if it is. It will only get overwritten anyway.
This commit is contained in:
parent
ddf2757cb6
commit
4dcc3c3b69
2 changed files with 20 additions and 8 deletions
|
@ -30,8 +30,6 @@ import org.oxycblt.auxio.music.Song
|
|||
import org.oxycblt.auxio.settings.SettingsManager
|
||||
import org.oxycblt.auxio.util.logD
|
||||
import org.oxycblt.auxio.util.logE
|
||||
import kotlin.math.max
|
||||
import kotlin.math.min
|
||||
|
||||
/**
|
||||
* Master class (and possible god object) for the playback state.
|
||||
|
@ -319,7 +317,11 @@ class PlaybackStateManager private constructor() {
|
|||
* Add a [song] to the top of the queue.
|
||||
*/
|
||||
fun playNext(song: Song) {
|
||||
mQueue.add(min(mIndex + 1, max(mQueue.lastIndex, 0)), song)
|
||||
if (mQueue.isEmpty()) {
|
||||
return
|
||||
}
|
||||
|
||||
mQueue.add(mIndex + 1, song)
|
||||
pushQueueUpdate()
|
||||
}
|
||||
|
||||
|
@ -327,7 +329,11 @@ class PlaybackStateManager private constructor() {
|
|||
* Add a list of [songs] to the top of the queue.
|
||||
*/
|
||||
fun playNext(songs: List<Song>) {
|
||||
mQueue.addAll(min(mIndex + 1, max(mQueue.lastIndex, 0)), songs)
|
||||
if (mQueue.isEmpty()) {
|
||||
return
|
||||
}
|
||||
|
||||
mQueue.addAll(mIndex + 1, songs)
|
||||
pushQueueUpdate()
|
||||
}
|
||||
|
||||
|
|
|
@ -43,6 +43,7 @@ class AudioReactor(
|
|||
private val callback: (Float) -> Unit
|
||||
) : AudioManager.OnAudioFocusChangeListener, SettingsManager.Callback {
|
||||
private data class Gain(val track: Float, val album: Float)
|
||||
private data class GainTag(val key: String, val value: Float)
|
||||
|
||||
private val playbackManager = PlaybackStateManager.getInstance()
|
||||
private val settingsManager = SettingsManager.getInstance()
|
||||
|
@ -60,6 +61,8 @@ class AudioReactor(
|
|||
.build()
|
||||
|
||||
private var pauseWasTransient = false
|
||||
|
||||
// It's good to keep the volume and the ducking multiplier separate so that we can
|
||||
private var multiplier = 1f
|
||||
set(value) {
|
||||
field = value
|
||||
|
@ -103,17 +106,21 @@ class AudioReactor(
|
|||
return
|
||||
}
|
||||
|
||||
// User wants track gain to be preferred
|
||||
// User wants track gain to be preferred. Default to album gain only if there
|
||||
// is no track gain.
|
||||
ReplayGainMode.TRACK ->
|
||||
{ gain ->
|
||||
gain.track == 0f
|
||||
}
|
||||
|
||||
// User wants album gain to be preferred. Default to track gain only if there
|
||||
// is no album gain.
|
||||
ReplayGainMode.ALBUM ->
|
||||
{ gain ->
|
||||
gain.album != 0f
|
||||
}
|
||||
|
||||
// User wants album gain to be used when in an album, track gain otherwise.
|
||||
ReplayGainMode.DYNAMIC ->
|
||||
{ _ ->
|
||||
playbackManager.parent is Album &&
|
||||
|
@ -131,6 +138,7 @@ class AudioReactor(
|
|||
gain.track
|
||||
}
|
||||
} else {
|
||||
// No gain tags were present
|
||||
0f
|
||||
}
|
||||
|
||||
|
@ -140,8 +148,6 @@ class AudioReactor(
|
|||
}
|
||||
|
||||
private fun parseReplayGain(metadata: Metadata): Gain? {
|
||||
data class GainTag(val key: String, val value: Float)
|
||||
|
||||
var trackGain = 0f
|
||||
var albumGain = 0f
|
||||
var found = false
|
||||
|
@ -213,7 +219,7 @@ class AudioReactor(
|
|||
}
|
||||
|
||||
/**
|
||||
* Abandon the current focus request, functionally "Destroying it".
|
||||
* Abandon the current focus request and any callbacks
|
||||
*/
|
||||
fun release() {
|
||||
AudioManagerCompat.abandonAudioFocusRequest(audioManager, request)
|
||||
|
|
Loading…
Reference in a new issue