all: fix misc issues

Fix miscellanious issues with documentation and the playback system
This commit is contained in:
OxygenCobalt
2022-05-20 11:30:56 -06:00
parent 9edc113ebb
commit 059652d2f1
12 changed files with 50 additions and 33 deletions
@@ -32,7 +32,7 @@ import org.oxycblt.auxio.music.Song
* Pretty much each service component needs to load bitmaps of some kind, but doing a blind image
* request with some target callbacks could result in overlapping requests causing unrelated
* updates. This class (to an extent) resolves this by keeping track of the current request and
* disposes of it every time a new request is created. This greatly reduces the surface for race
* disposing of it every time a new request is created. This greatly reduces the surface for race
* conditions save the case of instruction-by-instruction data races, which are effectively
* impossible to solve.
*
@@ -136,7 +136,6 @@ object Indexer {
*/
private fun loadSongs(context: Context): List<Song> {
val excludedDatabase = ExcludedDatabase.getInstance(context)
val paths = excludedDatabase.readPaths()
var selector = "${MediaStore.Audio.Media.IS_MUSIC}=1"
val args = mutableListOf<String>()
@@ -189,14 +188,14 @@ object Indexer {
val title = cursor.getString(titleIndex)
// Try to use the DISPLAY_NAME field to obtain a (probably sane) file name
// from the android system. Once gain though, OEM issues get in our way and
// from the android system. Once again though, OEM issues get in our way and
// this field isn't available on some platforms. In that case, see if we can
// grok a file name from the DATA field.
val fileName =
cursor.getStringOrNull(fileIndex)
?: cursor.getStringOrNull(dataIndex)?.run {
substringAfterLast('/', "").ifEmpty { null }
}
?: cursor
.getStringOrNull(dataIndex)
?.substringAfterLast('/', MediaStore.UNKNOWN_STRING)
?: MediaStore.UNKNOWN_STRING
// The TRACK field is for some reason formatted as DTTT, where D is the disk
@@ -51,6 +51,7 @@ sealed class Music : Item() {
* [Album] or [Artist]
*/
sealed class MusicParent : Music() {
/** The songs that this parent owns. */
abstract val songs: List<Song>
}
@@ -36,7 +36,6 @@ import org.oxycblt.auxio.playback.state.RepeatMode
import org.oxycblt.auxio.ui.MainNavigationAction
import org.oxycblt.auxio.ui.NavigationViewModel
import org.oxycblt.auxio.ui.ViewBindingFragment
import org.oxycblt.auxio.util.clamp
import org.oxycblt.auxio.util.formatDuration
import org.oxycblt.auxio.util.getAttrColorSafe
import org.oxycblt.auxio.util.logD
@@ -187,8 +186,7 @@ class PlaybackPanelFragment :
binding.playbackDuration.textSafe = seconds.formatDuration(false)
binding.playbackSeekBar.apply {
isEnabled = seconds > 0L
valueTo = max(seconds, 1L).toFloat()
value = seconds.clamp(0, valueTo.toLong()).toFloat()
valueToSafe = max(seconds, 1L).toFloat()
}
}
@@ -202,7 +200,7 @@ class PlaybackPanelFragment :
// around.
val binding = requireBinding()
if (!binding.playbackPosition.isActivated) {
binding.playbackSeekBar.value = position.toFloat()
binding.playbackSeekBar.valueSafe = position.toFloat()
binding.playbackPosition.textSafe = position.formatDuration(true)
}
}
@@ -221,4 +219,26 @@ class PlaybackPanelFragment :
private fun updateShuffled(isShuffled: Boolean) {
requireBinding().playbackShuffle.isActivated = isShuffled
}
private var Slider.valueSafe: Float
get() = value
set(v) {
value =
if (v > valueTo) {
valueTo
} else {
v
}
}
private var Slider.valueToSafe: Float
get() = valueTo
set(v) {
valueTo =
if (value > v) {
value
} else {
v
}
}
}
@@ -294,6 +294,7 @@ class PlaybackViewModel : ViewModel(), PlaybackStateManager.Callback {
private fun restorePlaybackState() {
logD("Attempting to restore playback state")
onNewPlayback(playbackManager.index, playbackManager.queue, playbackManager.parent)
onPositionChanged(playbackManager.positionMs)
onPlayingChanged(playbackManager.isPlaying)
onShuffledChanged(playbackManager.isShuffled)
@@ -127,7 +127,6 @@ class PlaybackStateManager private constructor() {
applyNewQueue(library, settingsManager.keepShuffle && isShuffled, song)
notifyNewPlayback()
notifyShuffledChanged()
seekTo(0)
isPlaying = true
isInitialized = true
}
@@ -142,7 +141,6 @@ class PlaybackStateManager private constructor() {
applyNewQueue(library, shuffled, null)
notifyNewPlayback()
notifyShuffledChanged()
seekTo(0)
isPlaying = true
isInitialized = true
}
@@ -154,7 +152,6 @@ class PlaybackStateManager private constructor() {
applyNewQueue(library, true, null)
notifyNewPlayback()
notifyShuffledChanged()
seekTo(0)
isPlaying = true
isInitialized = true
}
@@ -186,7 +183,6 @@ class PlaybackStateManager private constructor() {
private fun goto(idx: Int, play: Boolean) {
index = idx
notifyIndexMoved()
seekTo(0)
isPlaying = play
}
@@ -262,9 +258,11 @@ class PlaybackStateManager private constructor() {
sort.songsInPlace(newQueue)
newIndex = keep?.let(queue::indexOf) ?: 0
newIndex = keep?.let(newQueue::indexOf) ?: 0
}
logD("$newIndex $newQueue")
_queue = newQueue
index = newIndex
isShuffled = shuffled
@@ -24,7 +24,6 @@ import android.os.SystemClock
import android.support.v4.media.MediaMetadataCompat
import android.support.v4.media.session.MediaSessionCompat
import android.support.v4.media.session.PlaybackStateCompat
import androidx.media.session.MediaButtonReceiver
import com.google.android.exoplayer2.Player
import org.oxycblt.auxio.coil.BitmapProvider
import org.oxycblt.auxio.music.MusicParent
@@ -56,10 +55,6 @@ class MediaSessionComponent(private val context: Context, private val player: Pl
mediaSession.setCallback(this)
}
fun handleMediaButtonIntent(intent: Intent) {
MediaButtonReceiver.handleIntent(mediaSession, intent)
}
fun release() {
provider.release()
player.removeListener(this)
@@ -262,6 +262,7 @@ class PlaybackService :
}
logD("Loading ${song.rawName}")
player.seekTo(0)
player.setMediaItem(MediaItem.fromUri(song.uri))
player.prepare()
notificationComponent.updateMetadata(song, playbackManager.parent)