properly fetch duration from content uris
This commit is contained in:
parent
5be5de3dac
commit
b73bebf085
1 changed files with 5 additions and 5 deletions
|
@ -705,18 +705,18 @@ fun Context.getVideoResolution(path: String): Point? {
|
|||
|
||||
fun Context.getDuration(path: String): Int? {
|
||||
val projection = arrayOf(
|
||||
Video.Media.DURATION
|
||||
MediaColumns.DURATION
|
||||
)
|
||||
|
||||
val uri = Files.getContentUri("external")
|
||||
val selection = "${Video.Media.DATA} = ?"
|
||||
val selectionArgs = arrayOf(path)
|
||||
val uri = getFileUri(path)
|
||||
val selection = if (path.startsWith("content://")) "${BaseColumns._ID} = ?" else "${MediaColumns.DATA} = ?"
|
||||
val selectionArgs = if (path.startsWith("content://")) arrayOf(path.substringAfterLast("/")) else arrayOf(path)
|
||||
|
||||
try {
|
||||
val cursor = contentResolver.query(uri, projection, selection, selectionArgs, null)
|
||||
cursor?.use {
|
||||
if (cursor.moveToFirst()) {
|
||||
return Math.round(cursor.getIntValue(Video.Media.DURATION) / 1000.toDouble()).toInt()
|
||||
return Math.round(cursor.getIntValue(MediaColumns.DURATION) / 1000.toDouble()).toInt()
|
||||
}
|
||||
}
|
||||
} catch (ignored: Exception) {
|
||||
|
|
Loading…
Reference in a new issue