Skip to content

Commit

Permalink
Merge pull request #16 from Kin69/main
Browse files Browse the repository at this point in the history
Add Bitrate
  • Loading branch information
sosauce authored Jun 2, 2024
2 parents cf0bdf1 + afa222a commit 4415338
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
Expand All @@ -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<IntentSenderRequest>,
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@
<string name="about">A Propos</string>
<string name="size">Taille</string>
<string name="type">Type</string>
<string name="bitrate">Bitrate</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@
<string name="about">About</string>
<string name="size">Size</string>
<string name="type">Type</string>
<string name="bitrate">Bitrate</string>
</resources>

0 comments on commit 4415338

Please sign in to comment.