Merge pull request #4353 from SpiritCroc/video-compression

Fix broken video compression due to NPE in library
This commit is contained in:
Benoit Marty 2021-11-02 13:28:52 +01:00 committed by GitHub
commit 3760401b10
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 2 deletions

1
changelog.d/4353.bugfix Normal file
View File

@ -0,0 +1 @@
Fix video compression before upload

View File

@ -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
}
}

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%")