mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-12-02 09:18:00 +01:00
improving the way video durations are fetched, should be a lot quicker
This commit is contained in:
parent
a4c1da2ac6
commit
69addc428a
6 changed files with 53 additions and 65 deletions
|
@ -78,7 +78,7 @@ android {
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation 'com.simplemobiletools:commons:5.27.2'
|
implementation 'com.simplemobiletools:commons:5.27.3'
|
||||||
implementation 'com.theartofdev.edmodo:android-image-cropper:2.8.0'
|
implementation 'com.theartofdev.edmodo:android-image-cropper:2.8.0'
|
||||||
implementation 'androidx.multidex:multidex:2.0.1'
|
implementation 'androidx.multidex:multidex:2.0.1'
|
||||||
implementation 'it.sephiroth.android.exif:library:1.0.1'
|
implementation 'it.sephiroth.android.exif:library:1.0.1'
|
||||||
|
|
|
@ -389,7 +389,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
}
|
}
|
||||||
|
|
||||||
val isFavorite = favoritesDB.isFavorite(mPath)
|
val isFavorite = favoritesDB.isFavorite(mPath)
|
||||||
val duration = if (type == TYPE_VIDEOS) mPath.getVideoDuration() else 0
|
val duration = if (type == TYPE_VIDEOS) getVideoDuration(mPath) ?: 0 else 0
|
||||||
val ts = System.currentTimeMillis()
|
val ts = System.currentTimeMillis()
|
||||||
val medium = Medium(null, mPath.getFilenameFromPath(), mPath, mPath.getParentPath(), ts, ts, File(mPath).length(), type, duration, isFavorite, 0)
|
val medium = Medium(null, mPath.getFilenameFromPath(), mPath, mPath.getParentPath(), ts, ts, File(mPath).length(), type, duration, isFavorite, 0)
|
||||||
mediaDB.insert(medium)
|
mediaDB.insert(medium)
|
||||||
|
|
|
@ -789,7 +789,7 @@ fun Context.addPathToDB(path: String) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
val isFavorite = favoritesDB.isFavorite(path)
|
val isFavorite = favoritesDB.isFavorite(path)
|
||||||
val videoDuration = if (type == TYPE_VIDEOS) path.getVideoDuration() else 0
|
val videoDuration = if (type == TYPE_VIDEOS) getVideoDuration(path) ?: 0 else 0
|
||||||
val medium = Medium(null, path.getFilenameFromPath(), path, path.getParentPath(), System.currentTimeMillis(), System.currentTimeMillis(),
|
val medium = Medium(null, path.getFilenameFromPath(), path, path.getParentPath(), System.currentTimeMillis(), System.currentTimeMillis(),
|
||||||
File(path).length(), type, videoDuration, isFavorite, 0L)
|
File(path).length(), type, videoDuration, isFavorite, 0L)
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package com.simplemobiletools.gallery.pro.extensions
|
package com.simplemobiletools.gallery.pro.extensions
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.media.MediaMetadataRetriever
|
|
||||||
import android.os.Environment
|
import android.os.Environment
|
||||||
import com.simplemobiletools.commons.extensions.containsNoMedia
|
import com.simplemobiletools.commons.extensions.containsNoMedia
|
||||||
import com.simplemobiletools.commons.extensions.doesParentHaveNoMedia
|
import com.simplemobiletools.commons.extensions.doesParentHaveNoMedia
|
||||||
|
@ -67,15 +66,4 @@ fun String.getDistinctPath(): String {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun String.getVideoDuration(): Int {
|
|
||||||
var seconds = 0
|
|
||||||
try {
|
|
||||||
val retriever = MediaMetadataRetriever()
|
|
||||||
retriever.setDataSource(this)
|
|
||||||
seconds = Math.round(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION).toInt() / 1000f)
|
|
||||||
} catch (e: Exception) {
|
|
||||||
}
|
|
||||||
return seconds
|
|
||||||
}
|
|
||||||
|
|
||||||
fun String.isDownloadsFolder() = equals(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).toString(), true)
|
fun String.isDownloadsFolder() = equals(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).toString(), true)
|
||||||
|
|
|
@ -29,7 +29,6 @@ import com.simplemobiletools.gallery.pro.R
|
||||||
import com.simplemobiletools.gallery.pro.activities.PanoramaVideoActivity
|
import com.simplemobiletools.gallery.pro.activities.PanoramaVideoActivity
|
||||||
import com.simplemobiletools.gallery.pro.activities.VideoActivity
|
import com.simplemobiletools.gallery.pro.activities.VideoActivity
|
||||||
import com.simplemobiletools.gallery.pro.extensions.config
|
import com.simplemobiletools.gallery.pro.extensions.config
|
||||||
import com.simplemobiletools.gallery.pro.extensions.getVideoDuration
|
|
||||||
import com.simplemobiletools.gallery.pro.extensions.hasNavBar
|
import com.simplemobiletools.gallery.pro.extensions.hasNavBar
|
||||||
import com.simplemobiletools.gallery.pro.extensions.parseFileChannel
|
import com.simplemobiletools.gallery.pro.extensions.parseFileChannel
|
||||||
import com.simplemobiletools.gallery.pro.helpers.*
|
import com.simplemobiletools.gallery.pro.helpers.*
|
||||||
|
@ -688,7 +687,8 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
|
||||||
|
|
||||||
private fun setupVideoDuration() {
|
private fun setupVideoDuration() {
|
||||||
ensureBackgroundThread {
|
ensureBackgroundThread {
|
||||||
mDuration = mMedium.path.getVideoDuration()
|
mDuration = context?.getVideoDuration(mMedium.path) ?: 0
|
||||||
|
|
||||||
activity?.runOnUiThread {
|
activity?.runOnUiThread {
|
||||||
setupTimeHolder()
|
setupTimeHolder()
|
||||||
setPosition(0)
|
setPosition(0)
|
||||||
|
|
|
@ -294,7 +294,7 @@ class MediaFetcher(val context: Context) {
|
||||||
} else {
|
} else {
|
||||||
val lastModified = if (getProperLastModified) file.lastModified() else 0L
|
val lastModified = if (getProperLastModified) file.lastModified() else 0L
|
||||||
var dateTaken = lastModified
|
var dateTaken = lastModified
|
||||||
val videoDuration = if (getVideoDurations && isVideo) path.getVideoDuration() else 0
|
val videoDuration = if (getVideoDurations && isVideo) context.getVideoDuration(path) ?: 0 else 0
|
||||||
|
|
||||||
if (getProperDateTaken) {
|
if (getProperDateTaken) {
|
||||||
var newDateTaken = dateTakens.remove(path)
|
var newDateTaken = dateTakens.remove(path)
|
||||||
|
@ -383,7 +383,7 @@ class MediaFetcher(val context: Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
val path = Uri.decode(file.uri.toString().replaceFirst("${context.config.OTGTreeUri}/document/${context.config.OTGPartition}%3A", "${context.config.OTGPath}/"))
|
val path = Uri.decode(file.uri.toString().replaceFirst("${context.config.OTGTreeUri}/document/${context.config.OTGPartition}%3A", "${context.config.OTGPath}/"))
|
||||||
val videoDuration = if (getVideoDurations) path.getVideoDuration() else 0
|
val videoDuration = if (getVideoDurations) context.getVideoDuration(path) ?: 0 else 0
|
||||||
val isFavorite = favoritePaths.contains(path)
|
val isFavorite = favoritePaths.contains(path)
|
||||||
val medium = Medium(null, filename, path, folder, dateModified, dateTaken, size, type, videoDuration, isFavorite, 0L)
|
val medium = Medium(null, filename, path, folder, dateModified, dateTaken, size, type, videoDuration, isFavorite, 0L)
|
||||||
media.add(medium)
|
media.add(medium)
|
||||||
|
|
Loading…
Reference in a new issue