diff --git a/changelog.d/4353.bugfix b/changelog.d/4353.bugfix new file mode 100644 index 0000000000..170dbed418 --- /dev/null +++ b/changelog.d/4353.bugfix @@ -0,0 +1 @@ +Fix video compression before upload diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/content/UploadContentWorker.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/content/UploadContentWorker.kt index 0c5a90ca60..b657d950bd 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/content/UploadContentWorker.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/content/UploadContentWorker.kt @@ -214,8 +214,11 @@ internal class UploadContentWorker(val context: Context, params: WorkerParameter .also { filesToDelete.add(it) } } VideoCompressionResult.CompressionNotNeeded, - VideoCompressionResult.CompressionCancelled, + VideoCompressionResult.CompressionCancelled -> { + workingFile + } is VideoCompressionResult.CompressionFailed -> { + Timber.e(videoCompressionResult.failure, "Video compression failed") workingFile } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/content/VideoCompressor.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/content/VideoCompressor.kt index 05aaf4e9f1..a43f8abf33 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/content/VideoCompressor.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/content/VideoCompressor.kt @@ -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%")