mirror of
https://github.com/austinried/subtracks.git
synced 2026-11-10 15:11:58 +01:00
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:
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user