From afa222a1d0b93ad1c77c3b3d6d6eae49475353ea Mon Sep 17 00:00:00 2001 From: Kin69 Date: Sat, 1 Jun 2024 21:37:28 +0200 Subject: [PATCH] Add Bitrate --- .../components/BottomSheetContent.kt | 19 +++++++++++++++++++ app/src/main/res/values-fr/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + 3 files changed, 21 insertions(+) diff --git a/app/src/main/java/com/sosauce/cutemusic/components/BottomSheetContent.kt b/app/src/main/java/com/sosauce/cutemusic/components/BottomSheetContent.kt index 000f6ac..839264f 100644 --- a/app/src/main/java/com/sosauce/cutemusic/components/BottomSheetContent.kt +++ b/app/src/main/java/com/sosauce/cutemusic/components/BottomSheetContent.kt @@ -2,6 +2,7 @@ package com.sosauce.cutemusic.components import android.content.ContentValues import android.content.Context +import android.media.MediaMetadataRetriever import android.net.Uri import android.os.Build import android.provider.MediaStore @@ -56,6 +57,7 @@ fun BottomSheetContent(music: Music) { var art: ByteArray? by remember { mutableStateOf(byteArrayOf()) } val fileType = context.contentResolver.getType(music.uri) val fileSize = getFileSize(context, music.uri).formatBinarySize() + val fileBitrate = getFileBitrate(context, music.uri) LaunchedEffect(music.uri) { @@ -135,6 +137,11 @@ fun BottomSheetContent(music: Music) { fontFamily = GlobalFont, modifier = Modifier.padding(bottom = 5.dp) ) + Text( + text = "${stringResource(id = R.string.bitrate)}: $fileBitrate", + fontFamily = GlobalFont, + modifier = Modifier.padding(bottom = 5.dp) + ) Text( text = "${stringResource(id = R.string.type)}: $fileType", fontFamily = GlobalFont, @@ -158,6 +165,18 @@ private fun getFileSize(context: Context, uri: Uri): Long { return size } +private fun getFileBitrate(context: Context, uri: Uri): String { + val retriever = MediaMetadataRetriever() + return try { + retriever.setDataSource(context, uri) + val bitrate = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_BITRATE) + retriever.release() + bitrate?.toInt()?.div(1000)?.toString()?.plus(" kbps") ?: "Unknown" + } catch (e: Exception) { + "Unknown" + } +} + private fun createDeleteRequest( uri: Uri, intentSenderLauncher: ActivityResultLauncher, diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 2e688cb..b8479dd 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -14,4 +14,5 @@ A Propos Taille Type + Bitrate \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 4f26230..305053c 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -13,4 +13,5 @@ About Size Type + Bitrate \ No newline at end of file