show a bitrate the codecs do not report, and name LATM AAC

A decoder often gives no bitrate, so the row vanished; for a downloaded file the
size over the track length fills it in. The AAC mime Android and media3 use is
audio/mp4a-latm, which read as "MP4A-LATM" rather than AAC.
This commit is contained in:
austinried
2026-10-04 00:30:04 +00:00
parent 7b43b73592
commit 9a999498ab
3 changed files with 10 additions and 7 deletions
@@ -12,6 +12,7 @@ data class AudioEncoding(
null -> null
"audio/mpeg" -> "MP3"
"audio/mp4", "audio/m4a", "audio/x-m4a", "audio/aac" -> "AAC"
"audio/mp4a-latm", "audio/aac-adts", "audio/aac-latm" -> "AAC"
"audio/alac" -> "ALAC"
"audio/flac", "audio/x-flac" -> "FLAC"
"audio/ogg" -> "Ogg"
@@ -43,6 +43,8 @@ fun SongInfoDialog(
encoding = localFile?.let { readAudioEncoding(it) }
}
val shown = if (download?.status == DownloadStatus.Completed) encoding else streamEncoding
val sizeBytes = localFile?.length()?.takeIf { it > 0 }
val averageBps = sizeBytes?.let { bytes -> song.duration?.takeIf { it > 0 }?.let { seconds -> (bytes * 8 / seconds).toInt() } }
AlertDialog(
onDismissRequest = onDismiss,
title = { Text("Info") },
@@ -57,15 +59,14 @@ fun SongInfoDialog(
InfoRow("Starred", if (song.starred != null) "Yes" else null)
if (download != null) {
InfoRow("Download", downloadStatus(download.status))
InfoRow("Size", localFile?.length()?.takeIf { it > 0 }?.let { Formatter.formatFileSize(context, it) })
InfoRow("Size", sizeBytes?.let { Formatter.formatFileSize(context, it) })
download.error?.let { InfoRow("Error", it) }
}
shown?.let { enc ->
InfoRow("Format", enc.format)
InfoRow("Bitrate", enc.bitrate?.takeIf { it > 0 }?.let { "${it / 1000} kbps" })
InfoRow("Sample rate", enc.sampleRate?.takeIf { it > 0 }?.let { "$it Hz" })
InfoRow("Channels", enc.channels?.takeIf { it > 0 }?.toString())
}
InfoRow("Format", shown?.format)
// A decoder often reports no bitrate; the file's own size over the track length does.
InfoRow("Bitrate", (shown?.bitrate?.takeIf { it > 0 } ?: averageBps)?.let { "${it / 1000} kbps" })
InfoRow("Sample rate", shown?.sampleRate?.takeIf { it > 0 }?.let { "$it Hz" })
InfoRow("Channels", shown?.channels?.takeIf { it > 0 }?.toString())
}
},
confirmButton = { TextButton(onClick = onDismiss) { Text("Close") } },
@@ -10,6 +10,7 @@ class AudioEncodingTest {
assertEquals("MP3", AudioEncoding("audio/mpeg").format)
assertEquals("FLAC", AudioEncoding("audio/flac").format)
assertEquals("AAC", AudioEncoding("audio/mp4").format)
assertEquals("AAC", AudioEncoding("audio/mp4a-latm").format)
assertEquals("Opus", AudioEncoding("audio/opus").format)
}