11package com.simplemobiletools.filepicker.models
22
3- import android.content.Context
43import android.graphics.Bitmap
54import android.graphics.BitmapFactory
65import android.media.MediaMetadataRetriever
7- import android.net.Uri
8- import java.io.File
96import java.util.*
107
118class FileDirItem (val path : String , val name : String , val isDirectory : Boolean , val children : Int , val size : Long ) :
@@ -32,37 +29,37 @@ class FileDirItem(val path: String, val name: String, val isDirectory: Boolean,
3229 return options.outWidth != - 1 && options.outHeight != - 1
3330 }
3431
35- fun isVideo (context : Context ): Boolean {
36- return getMimeType(context ).startsWith(" video" )
32+ fun isVideo (): Boolean {
33+ return getMimeType().startsWith(" video" )
3734 }
3835
39- fun isAudio (context : Context ): Boolean {
40- return getMimeType(context ).startsWith(" audio" )
36+ fun isAudio (): Boolean {
37+ return getMimeType().startsWith(" audio" )
4138 }
4239
43- fun getMimeType (context : Context ): String {
40+ fun getMimeType (): String {
4441 try {
4542 val retriever = MediaMetadataRetriever ()
46- retriever.setDataSource(context, Uri .fromFile( File ( path)) )
43+ retriever.setDataSource(path)
4744 return retriever.extractMetadata(MediaMetadataRetriever .METADATA_KEY_MIMETYPE )
4845 } catch (ignored: Exception ) {
4946
5047 }
5148 return " "
5249 }
5350
54- fun getDuration (context : Context ): String {
51+ fun getDuration (): String {
5552 val retriever = MediaMetadataRetriever ()
56- retriever.setDataSource(context, Uri .fromFile( File ( path)) )
53+ retriever.setDataSource(path)
5754 val time = retriever.extractMetadata(MediaMetadataRetriever .METADATA_KEY_DURATION )
5855 val timeInMillisec = java.lang.Long .parseLong(time)
5956 return getFormattedDuration((timeInMillisec / 1000 ).toInt())
6057 }
6158
62- fun getVideoResolution (context : Context ): String {
59+ fun getVideoResolution (): String {
6360 try {
6461 val retriever = MediaMetadataRetriever ()
65- retriever.setDataSource(context, Uri .fromFile( File ( path)) )
62+ retriever.setDataSource(path)
6663 val width = retriever.extractMetadata(MediaMetadataRetriever .METADATA_KEY_VIDEO_WIDTH )
6764 val height = retriever.extractMetadata(MediaMetadataRetriever .METADATA_KEY_VIDEO_HEIGHT )
6865 return " $width x $height "
@@ -72,14 +69,13 @@ class FileDirItem(val path: String, val name: String, val isDirectory: Boolean,
7269 return " "
7370 }
7471
75- val imageResolution: String
76- get () {
77- val bitmap: Bitmap ? = BitmapFactory .decodeFile(path)
78- if (bitmap == null )
79- return " "
72+ fun getImageResolution (): String {
73+ val bitmap: Bitmap ? = BitmapFactory .decodeFile(path)
74+ if (bitmap == null )
75+ return " "
8076
81- return " ${bitmap.width} x ${bitmap.height} "
82- }
77+ return " ${bitmap.width} x ${bitmap.height} "
78+ }
8379
8480 private fun getFormattedDuration (duration : Int ): String {
8581 val sb = StringBuilder (8 )
0 commit comments