Skip to content

Commit

Permalink
feat: Display audio duration in MM:SS format
Browse files Browse the repository at this point in the history
Added extension functions to format audio duration:
- `toMinutes()`: Converts seconds to "MM:SS" format.
- `fromMillisToMinutes()`: Converts milliseconds to "MM:SS" format.

Updated MetadataEditorPage to display audio duration using `fromMillisToMinutes()` for accurate representation in minutes and seconds.
  • Loading branch information
BobbyESP committed Dec 1, 2024
1 parent a1b3ac3 commit f8a6584
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ import com.bobbyesp.ui.components.others.MetadataTag
import com.bobbyesp.ui.components.text.LargeCategoryTitle
import com.bobbyesp.ui.components.text.MarqueeText
import com.bobbyesp.ui.components.text.PreConfiguredOutlinedTextField
import com.bobbyesp.utilities.ext.fromMillisToMinutes
import com.bobbyesp.utilities.ext.isNeitherNullNorBlank
import com.bobbyesp.utilities.ext.toMinutes
import com.bobbyesp.utilities.states.ResourceState
Expand Down Expand Up @@ -438,7 +439,7 @@ private fun AudioProperties(modifier: Modifier = Modifier, audioProperties: Audi
MetadataTag(
modifier = Modifier.weight(0.5f),
typeOfMetadata = stringResource(id = R.string.duration),
metadata = audioProperties.length.toMinutes()
metadata = audioProperties.length.fromMillisToMinutes()
)
}
}
Expand Down
19 changes: 19 additions & 0 deletions app/utilities/src/main/java/com/bobbyesp/utilities/ext/Int.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,27 @@ fun Int.bigQuantityFormatter(): String {
}
}

/**
* Extension function to convert an integer representing seconds into a formatted string of minutes and seconds.
*
* @receiver Int The number of seconds to be converted.
* @return String The formatted string in "MM:SS" format.
*/
fun Int.toMinutes(): String {
val minutes = this / 60
val seconds = this % 60
return "%02d:%02d".format(minutes, seconds)
}

/**
* Extension function to convert an integer representing milliseconds into a formatted string of minutes and seconds.
*
* @receiver Int The number of milliseconds to be converted.
* @return String The formatted string in "MM:SS" format.
*/
fun Int.fromMillisToMinutes(): String {
val totalSeconds = this / 1000
val minutes = totalSeconds / 60
val seconds = totalSeconds % 60
return "%02d:%02d".format(minutes, seconds)
}

0 comments on commit f8a6584

Please sign in to comment.