Add Bundle extensions
This commit is contained in:
@@ -262,7 +262,7 @@ class PlayerService : Service(), Player.Listener, PlaybackStatsListener.Callback
|
||||
if (preferences.volumeNormalization) {
|
||||
player.volume = player.currentMediaItem?.let { mediaItem ->
|
||||
songPendingLoudnessDb.getOrElse(mediaItem.mediaId) {
|
||||
mediaItem.mediaMetadata.extras?.getFloat("loudnessDb")
|
||||
mediaItem.mediaMetadata.extras?.getFloatOrNull("loudnessDb")
|
||||
}?.takeIf { it > 0 }?.let { loudnessDb ->
|
||||
(1f - (0.01f + loudnessDb / 14)).coerceIn(0.1f, 1f)
|
||||
}
|
||||
|
||||
@@ -283,6 +283,18 @@ fun PlayerView(
|
||||
mutableStateOf(binder?.cache?.getCachedBytes(song?.id ?: "", 0, -1) ?: 0L)
|
||||
}
|
||||
|
||||
val loudnessDb by remember {
|
||||
derivedStateOf {
|
||||
song?.loudnessDb ?: playerState.mediaMetadata.extras?.getFloatOrNull("loudnessDb")
|
||||
}
|
||||
}
|
||||
|
||||
val contentLength by remember {
|
||||
derivedStateOf {
|
||||
song?.contentLength ?: playerState.mediaMetadata.extras?.getLongOrNull("contentLength")
|
||||
}
|
||||
}
|
||||
|
||||
DisposableEffect(song?.id) {
|
||||
val listener = object : Cache.Listener {
|
||||
override fun onSpanAdded(cache: Cache, span: CacheSpan) {
|
||||
@@ -363,13 +375,13 @@ fun PlayerView(
|
||||
style = typography.xs.semiBold.color(BlackColorPalette.text)
|
||||
)
|
||||
BasicText(
|
||||
text = song?.loudnessDb?.let { loudnessDb ->
|
||||
text = loudnessDb?.let { loudnessDb ->
|
||||
"%.2f dB".format(loudnessDb)
|
||||
} ?: "Unknown",
|
||||
style = typography.xs.semiBold.color(BlackColorPalette.text)
|
||||
)
|
||||
BasicText(
|
||||
text = song?.contentLength?.let { contentLength ->
|
||||
text = contentLength?.let { contentLength ->
|
||||
Formatter.formatShortFileSize(
|
||||
context,
|
||||
contentLength
|
||||
@@ -381,7 +393,7 @@ fun PlayerView(
|
||||
text = buildString {
|
||||
append(Formatter.formatShortFileSize(context, cachedBytes))
|
||||
|
||||
song?.contentLength?.let { contentLength ->
|
||||
contentLength?.let { contentLength ->
|
||||
append(" (${(cachedBytes.toFloat() / contentLength * 100).roundToInt()}%)")
|
||||
}
|
||||
},
|
||||
@@ -390,7 +402,7 @@ fun PlayerView(
|
||||
}
|
||||
}
|
||||
|
||||
if (song != null && (song?.contentLength == null || song?.loudnessDb == null)) {
|
||||
if (song != null && (contentLength == null || loudnessDb == null)) {
|
||||
BasicText(
|
||||
text = "FILL MISSING DATA",
|
||||
style = typography.xxs.semiBold.color(BlackColorPalette.text),
|
||||
|
||||
11
app/src/main/kotlin/it/vfsfitvnm/vimusic/utils/Bundle.kt
Normal file
11
app/src/main/kotlin/it/vfsfitvnm/vimusic/utils/Bundle.kt
Normal file
@@ -0,0 +1,11 @@
|
||||
package it.vfsfitvnm.vimusic.utils
|
||||
|
||||
import android.os.Bundle
|
||||
|
||||
|
||||
fun Bundle.getFloatOrNull(key: String): Float? =
|
||||
if (containsKey(key)) getFloat(key) else null
|
||||
|
||||
|
||||
fun Bundle.getLongOrNull(key: String): Long? =
|
||||
if (containsKey(key)) getLong(key) else null
|
||||
@@ -45,8 +45,8 @@ fun Database.insert(mediaItem: MediaItem): Song {
|
||||
albumId = album?.id,
|
||||
durationText = mediaItem.mediaMetadata.extras?.getString("durationText")!!,
|
||||
thumbnailUrl = mediaItem.mediaMetadata.artworkUri!!.toString(),
|
||||
loudnessDb = mediaItem.mediaMetadata.extras?.getFloat("loudnessDb"),
|
||||
contentLength = mediaItem.mediaMetadata.extras?.getLong("contentLength"),
|
||||
loudnessDb = mediaItem.mediaMetadata.extras?.getFloatOrNull("loudnessDb"),
|
||||
contentLength = mediaItem.mediaMetadata.extras?.getLongOrNull("contentLength"),
|
||||
).also(::insert)
|
||||
|
||||
mediaItem.mediaMetadata.extras?.getStringArrayList("artistNames")?.let { artistNames ->
|
||||
|
||||
Reference in New Issue
Block a user