improving the way video resolution is fetched

This commit is contained in:
tibbi 2019-04-02 17:36:45 +02:00
parent daa7ceaffe
commit d258d4599b
5 changed files with 43 additions and 27 deletions

View file

@ -7,7 +7,7 @@ buildscript {
propMinSdkVersion = 21
propTargetSdkVersion = propCompileSdkVersion
propVersionCode = 1
propVersionName = '5.10.30'
propVersionName = '5.11.0'
kotlin_version = '1.3.21'
}

View file

@ -82,7 +82,7 @@ class PropertiesDialog() {
addProperty(R.string.files_count, "", R.id.properties_file_count)
}
fileDirItem.path.isImageSlow() -> {
fileDirItem.getResolution()?.let { addProperty(R.string.resolution, it.formatAsResolution()) }
fileDirItem.getResolution(activity)?.let { addProperty(R.string.resolution, it.formatAsResolution()) }
}
fileDirItem.path.isAudioSlow() -> {
fileDirItem.getDuration()?.let { addProperty(R.string.duration, it) }
@ -92,7 +92,7 @@ class PropertiesDialog() {
}
fileDirItem.path.isVideoSlow() -> {
fileDirItem.getDuration()?.let { addProperty(R.string.duration, it) }
fileDirItem.getResolution()?.let { addProperty(R.string.resolution, it.formatAsResolution()) }
fileDirItem.getResolution(activity)?.let { addProperty(R.string.resolution, it.formatAsResolution()) }
fileDirItem.getArtist()?.let { addProperty(R.string.artist, it) }
fileDirItem.getAlbum()?.let { addProperty(R.string.album, it) }
}

View file

@ -8,7 +8,9 @@ import android.content.Intent
import android.content.pm.PackageManager
import android.database.Cursor
import android.graphics.Color
import android.graphics.Point
import android.media.ExifInterface
import android.media.MediaMetadataRetriever
import android.media.RingtoneManager
import android.net.Uri
import android.os.Build
@ -603,3 +605,39 @@ fun Context.getCanAppBeUpgraded() = proPackages.contains(baseConfig.appId.remove
fun Context.getProUrl() = "https://play.google.com/store/apps/details?id=${baseConfig.appId.removeSuffix(".debug")}.pro"
fun Context.getTimeFormat() = if (baseConfig.use24HourFormat) TIME_FORMAT_24 else TIME_FORMAT_12
fun Context.getResolution(path: String): Point? {
return if (path.isImageFast() || path.isImageSlow()) {
path.getImageResolution()
} else if (path.isVideoFast() || path.isVideoSlow()) {
getVideoResolution(path)
} else {
null
}
}
fun Context.getVideoResolution(path: String): Point? {
var point = try {
val retriever = MediaMetadataRetriever()
retriever.setDataSource(path)
val width = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH).toInt()
val height = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT).toInt()
Point(width, height)
} catch (ignored: Exception) {
null
}
if (point == null && path.startsWith("content://", true)) {
try {
val fd = contentResolver.openFileDescriptor(Uri.parse(path), "r")?.fileDescriptor
val retriever = MediaMetadataRetriever()
retriever.setDataSource(fd)
val width = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH).toInt()
val height = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT).toInt()
point = Point(width, height)
} catch (ignored: Exception) {
}
}
return point
}

View file

@ -186,28 +186,6 @@ fun String.getFileSongTitle(): String? {
}
}
fun String.getResolution(): Point? {
return if (isImageFast() || isImageSlow()) {
getImageResolution()
} else if (isVideoFast() || isVideoSlow()) {
getVideoResolution()
} else {
null
}
}
fun String.getVideoResolution(): Point? {
return try {
val retriever = MediaMetadataRetriever()
retriever.setDataSource(this)
val width = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH).toInt()
val height = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT).toInt()
Point(width, height)
} catch (ignored: Exception) {
null
}
}
fun String.getImageResolution(): Point? {
val options = BitmapFactory.Options()
options.inJustDecodeBounds = true

View file

@ -77,9 +77,9 @@ open class FileDirItem(val path: String, val name: String = "", var isDirectory:
fun getSongTitle() = path.getFileSongTitle()
fun getResolution() = path.getResolution()
fun getResolution(context: Context) = context.getResolution(path)
fun getVideoResolution() = path.getVideoResolution()
fun getVideoResolution(context: Context) = context.getVideoResolution(path)
fun getImageResolution() = path.getImageResolution()
}