diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/player/PreviewGenerator.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/player/PreviewGenerator.kt index 0f47d009..8b417efc 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/player/PreviewGenerator.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/player/PreviewGenerator.kt @@ -2,7 +2,6 @@ package com.lagradost.cloudstream3.ui.player import android.content.Context import android.graphics.Bitmap -import android.media.MediaMetadataRetriever import android.net.Uri import android.util.Log import androidx.annotation.WorkerThread @@ -13,6 +12,7 @@ import kotlinx.coroutines.isActive import kotlin.math.absoluteValue import kotlin.math.ceil import kotlin.math.log2 +import wseemann.media.FFmpegMediaMetadataRetriever const val MAX_LOD = 6 const val MIN_LOD = 3 @@ -67,8 +67,7 @@ class PreviewGenerator { } } - // also check out https://github.com/wseemann/FFmpegMediaMetadataRetriever - private val retriever: MediaMetadataRetriever = MediaMetadataRetriever() + private val retriever: FFmpegMediaMetadataRetriever = FFmpegMediaMetadataRetriever() fun clear(keepCache: Boolean = false) { if (keepCache) return @@ -111,11 +110,11 @@ class PreviewGenerator { Log.i(TAG, "Started loading preview") val durationMs = - retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION)?.toLong() + retriever.extractMetadata(FFmpegMediaMetadataRetriever.METADATA_KEY_DURATION)?.toLong() ?: throw IllegalArgumentException("Bad video duration") val durationUs = (durationMs * 1000L).toFloat() - //val width = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH)?.toInt() ?: throw IllegalArgumentException("Bad video width") - //val height = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT)?.toInt() ?: throw IllegalArgumentException("Bad video height") + //val width = retriever.extractMetadata(FFmpegMediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH)?.toInt() ?: throw IllegalArgumentException("Bad video width") + //val height = retriever.extractMetadata(FFmpegMediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT)?.toInt() ?: throw IllegalArgumentException("Bad video height") // log2 # 10s durations in the video ~= how many segments we have val maxLod = ceil(log2((durationMs / 10_000).toFloat())).toInt().coerceIn(MIN_LOD, MAX_LOD) @@ -130,7 +129,7 @@ class PreviewGenerator { val frame = durationUs * fraction val img = retriever.getFrameAtTime( frame.toLong(), - MediaMetadataRetriever.OPTION_CLOSEST_SYNC + FFmpegMediaMetadataRetriever.OPTION_CLOSEST_SYNC ) if (!scope.isActive) return synchronized(images) { @@ -144,4 +143,4 @@ class PreviewGenerator { } } } -} \ No newline at end of file +}