Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/nightly-notes/2026-11-07-fix-stats-viewport.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
## Fixed
- Stats for nerds now shows the real size of the video window instead of -1x-1
Original file line number Diff line number Diff line change
Expand Up @@ -2693,6 +2693,7 @@ class EnhancedPlayerManager private constructor() {
bandwidthBitsPerSecond = bandwidthMeter?.bitrateEstimate ?: 0L,
decoderName = analyticsLogger?.activeDecoderName,
gainDb = audioFeaturesManager?.appliedLoudnessDb,
surfaceFrame = surfaceManager?.getSurfaceHolder()?.surfaceFrame,
)

fun getCastVideoStreams(): List<VideoStream> = availableVideoStreams
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package io.github.aedev.flow.player.stats

import android.graphics.Rect
import android.os.Build
import androidx.media3.common.Format
import androidx.media3.common.util.Size
import androidx.media3.common.util.UnstableApi
import androidx.media3.exoplayer.ExoPlayer

Expand All @@ -10,6 +12,7 @@ internal data class PlayerStatsReadings(
val bandwidthBitsPerSecond: Long,
val decoderName: String?,
val gainDb: Float?,
val surfaceFrame: Rect?,
)

@UnstableApi
Expand All @@ -24,7 +27,8 @@ internal object PlayerStatsReader {
client: String?,
): PlayerStatsSnapshot {
val counters = player.videoDecoderCounters?.also { it.ensureUpdated() }
val surface = player.surfaceSize
// The player can't measure a bare Surface and reports -1, so a SurfaceView's own frame comes first.
val viewport = readings.surfaceFrame?.let { Size(it.width(), it.height()) } ?: player.surfaceSize
return PlayerStatsSnapshot(
device = device,
videoId = videoId,
Expand All @@ -43,8 +47,8 @@ internal object PlayerStatsReader {
gainDb = readings.gainDb,
bandwidthBitsPerSecond = readings.bandwidthBitsPerSecond,
bufferedMs = player.totalBufferedDuration,
viewportWidth = surface.width,
viewportHeight = surface.height,
viewportWidth = viewport.width,
viewportHeight = viewport.height,
droppedFrames = counters?.droppedBufferCount ?: 0,
renderedFrames = counters?.renderedOutputBufferCount ?: 0,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,17 @@ internal object PlayerStatsFormatter {
PlayerStatLine(R.string.stats_volume, volume(snapshot)),
PlayerStatLine(R.string.stats_bandwidth, bandwidth(snapshot.bandwidthBitsPerSecond)),
PlayerStatLine(R.string.stats_buffered, String.format(Locale.US, "%.1f s", snapshot.bufferedMs / MS_PER_SECOND)),
PlayerStatLine(R.string.stats_viewport, "${snapshot.viewportWidth}x${snapshot.viewportHeight}"),
PlayerStatLine(R.string.stats_viewport, viewport(snapshot)),
PlayerStatLine(R.string.stats_dropped_frames, "${snapshot.droppedFrames} / ${snapshot.renderedFrames}"),
)

private fun viewport(snapshot: PlayerStatsSnapshot): String =
if (snapshot.viewportWidth > 0 && snapshot.viewportHeight > 0) {
"${snapshot.viewportWidth}x${snapshot.viewportHeight}"
} else {
UNKNOWN
}

private fun videoId(snapshot: PlayerStatsSnapshot): String =
listOfNotNull(snapshot.videoId, "[${snapshot.kind}]", snapshot.client).joinToString(" ")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ class PlayerStatsFormatterTest {
assertThat(value(full, R.string.stats_dropped_frames)).isEqualTo("18 / 4469")
}

@Test
fun `a viewport the player could not measure reads as unknown`() {
val unmeasured = full.copy(viewportWidth = -1, viewportHeight = -1)

assertThat(value(unmeasured, R.string.stats_viewport)).isEqualTo("-")
}

@Test
fun `a slow connection reads in kbps`() {
assertThat(value(full.copy(bandwidthBitsPerSecond = 640_000L), R.string.stats_bandwidth)).isEqualTo("640 kbps")
Expand Down
Loading