mirror of
https://github.com/SimpleMobileTools/Simple-Voice-Recorder.git
synced 2025-06-05 21:59:31 +02:00
handle fails at fetching alternative file duration and size gracefully
This commit is contained in:
@ -231,15 +231,23 @@ class PlayerFragment(context: Context, attributeSet: AttributeSet) : MyViewPager
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun getDurationFromUri(id: Long): Long {
|
private fun getDurationFromUri(id: Long): Long {
|
||||||
val retriever = MediaMetadataRetriever()
|
return try {
|
||||||
retriever.setDataSource(context, getAudioFileContentUri(id))
|
val retriever = MediaMetadataRetriever()
|
||||||
val time = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION)
|
retriever.setDataSource(context, getAudioFileContentUri(id))
|
||||||
return Math.round(time.toLong() / 1000.toDouble())
|
val time = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION)
|
||||||
|
Math.round(time.toLong() / 1000.toDouble())
|
||||||
|
} catch (e: Exception) {
|
||||||
|
0L
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getSizeFromUri(id: Long): Int {
|
private fun getSizeFromUri(id: Long): Int {
|
||||||
val recordingUri = getAudioFileContentUri(id)
|
val recordingUri = getAudioFileContentUri(id)
|
||||||
return context.contentResolver.openInputStream(recordingUri)?.available() ?: 0
|
return try {
|
||||||
|
context.contentResolver.openInputStream(recordingUri)?.available() ?: 0
|
||||||
|
} catch (e: Exception) {
|
||||||
|
0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun initMediaPlayer() {
|
private fun initMediaPlayer() {
|
||||||
|
Reference in New Issue
Block a user