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 { | ||||
|         return try { | ||||
|             val retriever = MediaMetadataRetriever() | ||||
|             retriever.setDataSource(context, getAudioFileContentUri(id)) | ||||
|             val time = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION) | ||||
|         return Math.round(time.toLong() / 1000.toDouble()) | ||||
|             Math.round(time.toLong() / 1000.toDouble()) | ||||
|         } catch (e: Exception) { | ||||
|             0L | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private fun getSizeFromUri(id: Long): Int { | ||||
|         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() { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user