Skip to content

Commit

Permalink
Merge pull request element-hq#4353 from SpiritCroc/video-compression
Browse files Browse the repository at this point in the history
Fix broken video compression due to NPE in library
  • Loading branch information
bmarty authored Nov 2, 2021
2 parents d1294f9 + c568595 commit 3760401
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions changelog.d/4353.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix video compression before upload
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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%")
Expand Down

0 comments on commit 3760401

Please sign in to comment.