Fix broken video compression

Library issue: https://github.com/natario1/Transcoder/issues/154

Change-Id: I4491e7e3fc541922ddc0fd3e407d608cd46a23f0
This commit is contained in:
SpiritCroc 2021-10-26 13:02:38 +02:00
parent 9cb746d509
commit 3d238d52d9
2 changed files with 14 additions and 1 deletions

View File

@ -188,6 +188,9 @@ internal class UploadContentWorker(val context: Context, params: WorkerParameter
}
})
.let { videoCompressionResult ->
if (videoCompressionResult is VideoCompressionResult.CompressionFailed) {
videoCompressionResult.failure.printStackTrace()
}
when (videoCompressionResult) {
is VideoCompressionResult.Success -> {
val compressedFile = videoCompressionResult.compressedFile

View File

@ -18,6 +18,7 @@ package org.matrix.android.sdk.internal.session.content
import com.otaliastudios.transcoder.Transcoder
import com.otaliastudios.transcoder.TranscoderListener
import com.otaliastudios.transcoder.source.FilePathDataSource
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.withContext
@ -43,7 +44,16 @@ internal class VideoCompressor @Inject constructor(
var result: Int = -1
var failure: Throwable? = null
Transcoder.into(destinationFile.path)
.addDataSource(videoFile.path)
.addDataSource(object: FilePathDataSource(videoFile.path) {
// https://github.com/natario1/Transcoder/issues/154
@Suppress("SENSELESS_COMPARISON") // Source is annotated as @NonNull, but can actually be null...
override fun isInitialized(): Boolean {
if (source == null) {
return false
}
return super.isInitialized()
}
})
.setListener(object : TranscoderListener {
override fun onTranscodeProgress(progress: Double) {
Timber.d("Compressing: $progress%")