Skip to content

Commit

Permalink
Show itag instead of volume in stats for nerds
Browse files Browse the repository at this point in the history
  • Loading branch information
vfsfitvnm committed Oct 29, 2022
1 parent accbfc4 commit 5c056a3
Showing 1 changed file with 24 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.unit.dp
import androidx.media3.common.Player
import androidx.media3.datasource.cache.Cache
import androidx.media3.datasource.cache.CacheSpan
import it.vfsfitvnm.innertube.Innertube
Expand All @@ -37,7 +36,6 @@ import it.vfsfitvnm.vimusic.models.Format
import it.vfsfitvnm.vimusic.ui.styling.LocalAppearance
import it.vfsfitvnm.vimusic.ui.styling.onOverlay
import it.vfsfitvnm.vimusic.ui.styling.overlay
import it.vfsfitvnm.vimusic.utils.DisposableListener
import it.vfsfitvnm.vimusic.utils.color
import it.vfsfitvnm.vimusic.utils.medium
import kotlin.math.roundToInt
Expand Down Expand Up @@ -75,7 +73,7 @@ fun StatsForNerds(
Database.format(mediaId).distinctUntilChanged().collectLatest {
if (it?.itag == null) {
withContext(Dispatchers.IO) {
delay(3000)
delay(2000)
Innertube.player(PlayerBody(videoId = mediaId))?.onSuccess { response ->
response.streamingData?.highestQualityFormat?.let { format ->
Database.insert(
Expand All @@ -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) {
val listener = object : Cache.Listener {
override fun onSpanAdded(cache: Cache, span: CacheSpan) {
Expand All @@ -120,11 +106,8 @@ fun StatsForNerds(
cachedBytes -= span.length
}

override fun onSpanTouched(
cache: Cache,
oldSpan: CacheSpan,
newSpan: CacheSpan
) = Unit
override fun onSpanTouched(cache: Cache, oldSpan: CacheSpan, newSpan: CacheSpan) =
Unit
}

binder.cache.addListener(mediaId, listener)
Expand Down Expand Up @@ -158,11 +141,7 @@ fun StatsForNerds(
style = typography.xs.medium.color(colorPalette.onOverlay)
)
BasicText(
text = "Volume",
style = typography.xs.medium.color(colorPalette.onOverlay)
)
BasicText(
text = "Loudness",
text = "Itag",
style = typography.xs.medium.color(colorPalette.onOverlay)
)
BasicText(
Expand All @@ -177,46 +156,48 @@ fun StatsForNerds(
text = "Cached",
style = typography.xs.medium.color(colorPalette.onOverlay)
)
BasicText(
text = "Loudness",
style = typography.xs.medium.color(colorPalette.onOverlay)
)
}

Column {
BasicText(
text = mediaId,
maxLines = 1,
style = typography.xs.medium.color(colorPalette.onOverlay)
)
BasicText(
text = "${volume.times(100).roundToInt()}%",
style = typography.xs.medium.color(colorPalette.onOverlay)
)
BasicText(
text = format?.loudnessDb?.let { loudnessDb ->
"%.2f dB".format(loudnessDb)
} ?: "Unknown",
text = format?.itag?.toString() ?: "Unknown",
maxLines = 1,
style = typography.xs.medium.color(colorPalette.onOverlay)
)
BasicText(
text = format?.bitrate?.let { bitrate ->
"${bitrate / 1000} kbps"
} ?: "Unknown",
text = format?.bitrate?.let { "${it / 1000} kbps" } ?: "Unknown",
maxLines = 1,
style = typography.xs.medium.color(colorPalette.onOverlay)
)
BasicText(
text = format?.contentLength?.let { contentLength ->
Formatter.formatShortFileSize(
context,
contentLength
)
} ?: "Unknown",
text = format?.contentLength
?.let { Formatter.formatShortFileSize(context, it) } ?: "Unknown",
maxLines = 1,
style = typography.xs.medium.color(colorPalette.onOverlay)
)
BasicText(
text = buildString {
append(Formatter.formatShortFileSize(context, cachedBytes))

format?.contentLength?.let { contentLength ->
append(" (${(cachedBytes.toFloat() / contentLength * 100).roundToInt()}%)")
format?.contentLength?.let {
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)
)
}
Expand Down

0 comments on commit 5c056a3

Please sign in to comment.