Do not resize video thumbnail.

This commit is contained in:
onurays 2020-03-25 17:35:18 +03:00
parent f9aed28732
commit f68e98b2c7
1 changed files with 1 additions and 13 deletions

View File

@ -22,8 +22,6 @@ import android.media.MediaMetadataRetriever
import im.vector.matrix.android.api.session.content.ContentAttachmentData import im.vector.matrix.android.api.session.content.ContentAttachmentData
import timber.log.Timber import timber.log.Timber
import java.io.ByteArrayOutputStream import java.io.ByteArrayOutputStream
import kotlin.math.max
import kotlin.math.roundToInt
internal object ThumbnailExtractor { internal object ThumbnailExtractor {
@ -48,17 +46,7 @@ internal object ThumbnailExtractor {
val mediaMetadataRetriever = MediaMetadataRetriever() val mediaMetadataRetriever = MediaMetadataRetriever()
try { try {
mediaMetadataRetriever.setDataSource(context, attachment.queryUri) mediaMetadataRetriever.setDataSource(context, attachment.queryUri)
var thumbnail = mediaMetadataRetriever.frameAtTime val thumbnail = mediaMetadataRetriever.frameAtTime
// Scale down the bitmap if it's too large.
val width: Int = thumbnail.width
val height: Int = thumbnail.height
val max = max(width, height)
if (max > 512) {
val scale = 512f / max
val w = (scale * width).roundToInt()
val h = (scale * height).roundToInt()
thumbnail = Bitmap.createScaledBitmap(thumbnail, w, h, true)
}
val outputStream = ByteArrayOutputStream() val outputStream = ByteArrayOutputStream()
thumbnail.compress(Bitmap.CompressFormat.JPEG, 100, outputStream) thumbnail.compress(Bitmap.CompressFormat.JPEG, 100, outputStream)