mirror of
https://github.com/SimpleMobileTools/Simple-File-Manager.git
synced 2025-06-05 22:09:15 +02:00
lets require only a file path, instead of FileDir for getting the properties
This commit is contained in:
@@ -1,9 +1,7 @@
|
||||
package com.simplemobiletools.filepicker.models
|
||||
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.BitmapFactory
|
||||
import android.media.MediaMetadataRetriever
|
||||
import java.util.*
|
||||
|
||||
class FileDirItem(val path: String, val name: String, val isDirectory: Boolean, val children: Int, val size: Long) :
|
||||
Comparable<FileDirItem> {
|
||||
@@ -24,7 +22,6 @@ class FileDirItem(val path: String, val name: String, val isDirectory: Boolean,
|
||||
|
||||
fun isGif() = name.toLowerCase().endsWith(".gif")
|
||||
fun isVideo() = getMimeType().startsWith("video")
|
||||
fun isAudio() = getMimeType().startsWith("audio")
|
||||
|
||||
fun isImage(): Boolean {
|
||||
val options = BitmapFactory.Options()
|
||||
@@ -43,48 +40,4 @@ class FileDirItem(val path: String, val name: String, val isDirectory: Boolean,
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
fun getDuration(): String {
|
||||
val retriever = MediaMetadataRetriever()
|
||||
retriever.setDataSource(path)
|
||||
val time = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION)
|
||||
val timeInMillisec = java.lang.Long.parseLong(time)
|
||||
return getFormattedDuration((timeInMillisec / 1000).toInt())
|
||||
}
|
||||
|
||||
fun getVideoResolution(): String {
|
||||
try {
|
||||
val retriever = MediaMetadataRetriever()
|
||||
retriever.setDataSource(path)
|
||||
val width = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH)
|
||||
val height = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT)
|
||||
return "$width x $height"
|
||||
} catch (ignored: Exception) {
|
||||
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
fun getImageResolution(): String {
|
||||
val bitmap: Bitmap? = BitmapFactory.decodeFile(path)
|
||||
if (bitmap == null)
|
||||
return ""
|
||||
|
||||
return "${bitmap.width} x ${bitmap.height}"
|
||||
}
|
||||
|
||||
private fun getFormattedDuration(duration: Int): String {
|
||||
val sb = StringBuilder(8)
|
||||
val hours = duration / (60 * 60)
|
||||
val minutes = duration % (60 * 60) / 60
|
||||
val seconds = duration % (60 * 60) % 60
|
||||
|
||||
if (duration > 3600) {
|
||||
sb.append(String.format(Locale.getDefault(), "%02d", hours)).append(":")
|
||||
}
|
||||
|
||||
sb.append(String.format(Locale.getDefault(), "%02d", minutes))
|
||||
sb.append(":").append(String.format(Locale.getDefault(), "%02d", seconds))
|
||||
return sb.toString()
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user