Show itag instead of volume in stats for nerds
This commit is contained in:
parent
accbfc47d0
commit
5c056a3b84
1 changed files with 24 additions and 43 deletions
|
@ -25,7 +25,6 @@ import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.input.pointer.pointerInput
|
import androidx.compose.ui.input.pointer.pointerInput
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.media3.common.Player
|
|
||||||
import androidx.media3.datasource.cache.Cache
|
import androidx.media3.datasource.cache.Cache
|
||||||
import androidx.media3.datasource.cache.CacheSpan
|
import androidx.media3.datasource.cache.CacheSpan
|
||||||
import it.vfsfitvnm.innertube.Innertube
|
import it.vfsfitvnm.innertube.Innertube
|
||||||
|
@ -37,7 +36,6 @@ import it.vfsfitvnm.vimusic.models.Format
|
||||||
import it.vfsfitvnm.vimusic.ui.styling.LocalAppearance
|
import it.vfsfitvnm.vimusic.ui.styling.LocalAppearance
|
||||||
import it.vfsfitvnm.vimusic.ui.styling.onOverlay
|
import it.vfsfitvnm.vimusic.ui.styling.onOverlay
|
||||||
import it.vfsfitvnm.vimusic.ui.styling.overlay
|
import it.vfsfitvnm.vimusic.ui.styling.overlay
|
||||||
import it.vfsfitvnm.vimusic.utils.DisposableListener
|
|
||||||
import it.vfsfitvnm.vimusic.utils.color
|
import it.vfsfitvnm.vimusic.utils.color
|
||||||
import it.vfsfitvnm.vimusic.utils.medium
|
import it.vfsfitvnm.vimusic.utils.medium
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
|
@ -75,7 +73,7 @@ fun StatsForNerds(
|
||||||
Database.format(mediaId).distinctUntilChanged().collectLatest {
|
Database.format(mediaId).distinctUntilChanged().collectLatest {
|
||||||
if (it?.itag == null) {
|
if (it?.itag == null) {
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
delay(3000)
|
delay(2000)
|
||||||
Innertube.player(PlayerBody(videoId = mediaId))?.onSuccess { response ->
|
Innertube.player(PlayerBody(videoId = mediaId))?.onSuccess { response ->
|
||||||
response.streamingData?.highestQualityFormat?.let { format ->
|
response.streamingData?.highestQualityFormat?.let { format ->
|
||||||
Database.insert(
|
Database.insert(
|
||||||
|
@ -98,18 +96,6 @@ fun StatsForNerds(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var volume by remember {
|
|
||||||
mutableStateOf(binder.player.volume)
|
|
||||||
}
|
|
||||||
|
|
||||||
binder.player.DisposableListener {
|
|
||||||
object : Player.Listener {
|
|
||||||
override fun onVolumeChanged(newVolume: Float) {
|
|
||||||
volume = newVolume
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
DisposableEffect(mediaId) {
|
DisposableEffect(mediaId) {
|
||||||
val listener = object : Cache.Listener {
|
val listener = object : Cache.Listener {
|
||||||
override fun onSpanAdded(cache: Cache, span: CacheSpan) {
|
override fun onSpanAdded(cache: Cache, span: CacheSpan) {
|
||||||
|
@ -120,11 +106,8 @@ fun StatsForNerds(
|
||||||
cachedBytes -= span.length
|
cachedBytes -= span.length
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onSpanTouched(
|
override fun onSpanTouched(cache: Cache, oldSpan: CacheSpan, newSpan: CacheSpan) =
|
||||||
cache: Cache,
|
Unit
|
||||||
oldSpan: CacheSpan,
|
|
||||||
newSpan: CacheSpan
|
|
||||||
) = Unit
|
|
||||||
}
|
}
|
||||||
|
|
||||||
binder.cache.addListener(mediaId, listener)
|
binder.cache.addListener(mediaId, listener)
|
||||||
|
@ -158,11 +141,7 @@ fun StatsForNerds(
|
||||||
style = typography.xs.medium.color(colorPalette.onOverlay)
|
style = typography.xs.medium.color(colorPalette.onOverlay)
|
||||||
)
|
)
|
||||||
BasicText(
|
BasicText(
|
||||||
text = "Volume",
|
text = "Itag",
|
||||||
style = typography.xs.medium.color(colorPalette.onOverlay)
|
|
||||||
)
|
|
||||||
BasicText(
|
|
||||||
text = "Loudness",
|
|
||||||
style = typography.xs.medium.color(colorPalette.onOverlay)
|
style = typography.xs.medium.color(colorPalette.onOverlay)
|
||||||
)
|
)
|
||||||
BasicText(
|
BasicText(
|
||||||
|
@ -177,46 +156,48 @@ fun StatsForNerds(
|
||||||
text = "Cached",
|
text = "Cached",
|
||||||
style = typography.xs.medium.color(colorPalette.onOverlay)
|
style = typography.xs.medium.color(colorPalette.onOverlay)
|
||||||
)
|
)
|
||||||
|
BasicText(
|
||||||
|
text = "Loudness",
|
||||||
|
style = typography.xs.medium.color(colorPalette.onOverlay)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
Column {
|
Column {
|
||||||
BasicText(
|
BasicText(
|
||||||
text = mediaId,
|
text = mediaId,
|
||||||
|
maxLines = 1,
|
||||||
style = typography.xs.medium.color(colorPalette.onOverlay)
|
style = typography.xs.medium.color(colorPalette.onOverlay)
|
||||||
)
|
)
|
||||||
BasicText(
|
BasicText(
|
||||||
text = "${volume.times(100).roundToInt()}%",
|
text = format?.itag?.toString() ?: "Unknown",
|
||||||
|
maxLines = 1,
|
||||||
style = typography.xs.medium.color(colorPalette.onOverlay)
|
style = typography.xs.medium.color(colorPalette.onOverlay)
|
||||||
)
|
)
|
||||||
BasicText(
|
BasicText(
|
||||||
text = format?.loudnessDb?.let { loudnessDb ->
|
text = format?.bitrate?.let { "${it / 1000} kbps" } ?: "Unknown",
|
||||||
"%.2f dB".format(loudnessDb)
|
maxLines = 1,
|
||||||
} ?: "Unknown",
|
|
||||||
style = typography.xs.medium.color(colorPalette.onOverlay)
|
style = typography.xs.medium.color(colorPalette.onOverlay)
|
||||||
)
|
)
|
||||||
BasicText(
|
BasicText(
|
||||||
text = format?.bitrate?.let { bitrate ->
|
text = format?.contentLength
|
||||||
"${bitrate / 1000} kbps"
|
?.let { Formatter.formatShortFileSize(context, it) } ?: "Unknown",
|
||||||
} ?: "Unknown",
|
maxLines = 1,
|
||||||
style = typography.xs.medium.color(colorPalette.onOverlay)
|
|
||||||
)
|
|
||||||
BasicText(
|
|
||||||
text = format?.contentLength?.let { contentLength ->
|
|
||||||
Formatter.formatShortFileSize(
|
|
||||||
context,
|
|
||||||
contentLength
|
|
||||||
)
|
|
||||||
} ?: "Unknown",
|
|
||||||
style = typography.xs.medium.color(colorPalette.onOverlay)
|
style = typography.xs.medium.color(colorPalette.onOverlay)
|
||||||
)
|
)
|
||||||
BasicText(
|
BasicText(
|
||||||
text = buildString {
|
text = buildString {
|
||||||
append(Formatter.formatShortFileSize(context, cachedBytes))
|
append(Formatter.formatShortFileSize(context, cachedBytes))
|
||||||
|
|
||||||
format?.contentLength?.let { contentLength ->
|
format?.contentLength?.let {
|
||||||
append(" (${(cachedBytes.toFloat() / contentLength * 100).roundToInt()}%)")
|
append(" (${(cachedBytes.toFloat() / it * 100).roundToInt()}%)")
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
maxLines = 1,
|
||||||
|
style = typography.xs.medium.color(colorPalette.onOverlay)
|
||||||
|
)
|
||||||
|
BasicText(
|
||||||
|
text = format?.loudnessDb?.let { "%.2f dB".format(it) } ?: "Unknown",
|
||||||
|
maxLines = 1,
|
||||||
style = typography.xs.medium.color(colorPalette.onOverlay)
|
style = typography.xs.medium.color(colorPalette.onOverlay)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue