mirror of
https://github.com/vector-im/element-android.git
synced 2024-11-15 01:35:07 +08:00
Change the library to compress video for licensing reason
This commit is contained in:
parent
9d225b7826
commit
6347564365
@ -48,8 +48,6 @@ allprojects {
|
|||||||
// Chat effects
|
// Chat effects
|
||||||
includeGroupByRegex 'com\\.github\\.jetradarmobile'
|
includeGroupByRegex 'com\\.github\\.jetradarmobile'
|
||||||
includeGroupByRegex 'nl\\.dionsegijn'
|
includeGroupByRegex 'nl\\.dionsegijn'
|
||||||
// LightCompressor
|
|
||||||
includeGroupByRegex 'com\\.github\\.AbedElazizShe'
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
maven {
|
maven {
|
||||||
|
@ -169,7 +169,7 @@ dependencies {
|
|||||||
implementation 'com.facebook.stetho:stetho-okhttp3:1.6.0'
|
implementation 'com.facebook.stetho:stetho-okhttp3:1.6.0'
|
||||||
|
|
||||||
// Video compression
|
// Video compression
|
||||||
implementation 'com.github.AbedElazizShe:LightCompressor:0.9.0'
|
implementation 'com.otaliastudios:transcoder:0.10.3'
|
||||||
|
|
||||||
// Phone number https://github.com/google/libphonenumber
|
// Phone number https://github.com/google/libphonenumber
|
||||||
implementation 'com.googlecode.libphonenumber:libphonenumber:8.12.22'
|
implementation 'com.googlecode.libphonenumber:libphonenumber:8.12.22'
|
||||||
|
@ -17,9 +17,8 @@
|
|||||||
package org.matrix.android.sdk.internal.session.content
|
package org.matrix.android.sdk.internal.session.content
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import com.abedelazizshe.lightcompressorlibrary.CompressionListener
|
import com.otaliastudios.transcoder.Transcoder
|
||||||
import com.abedelazizshe.lightcompressorlibrary.VideoCompressor
|
import com.otaliastudios.transcoder.TranscoderListener
|
||||||
import com.abedelazizshe.lightcompressorlibrary.VideoQuality
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
@ -31,51 +30,39 @@ import javax.inject.Inject
|
|||||||
|
|
||||||
internal class VideoCompressor @Inject constructor(private val context: Context) {
|
internal class VideoCompressor @Inject constructor(private val context: Context) {
|
||||||
suspend fun compress(videoFile: File,
|
suspend fun compress(videoFile: File,
|
||||||
progressListener: ProgressListener?,
|
progressListener: ProgressListener?): File {
|
||||||
quality: VideoQuality = VideoQuality.MEDIUM,
|
|
||||||
isMinBitRateEnabled: Boolean = false,
|
|
||||||
keepOriginalResolution: Boolean = true): File {
|
|
||||||
return withContext(Dispatchers.IO) {
|
return withContext(Dispatchers.IO) {
|
||||||
val job = Job()
|
val job = Job()
|
||||||
val destinationFile = createDestinationFile()
|
val destinationFile = createDestinationFile()
|
||||||
|
|
||||||
// Sadly it does not return the Job, the API is not ideal
|
Timber.d("Compressing: start")
|
||||||
VideoCompressor.start(
|
progressListener?.onProgress(0, 100)
|
||||||
context = null,
|
|
||||||
srcUri = null,
|
Transcoder.into(destinationFile.path)
|
||||||
srcPath = videoFile.path,
|
.addDataSource(videoFile.path)
|
||||||
destPath = destinationFile.path,
|
.setListener(object: TranscoderListener {
|
||||||
listener = object : CompressionListener {
|
override fun onTranscodeProgress(progress: Double) {
|
||||||
override fun onProgress(percent: Float) {
|
Timber.d("Compressing: $progress%")
|
||||||
Timber.d("Compressing: $percent%")
|
progressListener?.onProgress((progress * 100).toInt(), 100)
|
||||||
progressListener?.onProgress(percent.toInt(), 100)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onStart() {
|
override fun onTranscodeCompleted(successCode: Int) {
|
||||||
Timber.d("Compressing: start")
|
|
||||||
progressListener?.onProgress(0, 100)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onSuccess() {
|
|
||||||
Timber.d("Compressing: success")
|
Timber.d("Compressing: success")
|
||||||
progressListener?.onProgress(100, 100)
|
progressListener?.onProgress(100, 100)
|
||||||
job.complete()
|
job.complete()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onFailure(failureMessage: String) {
|
override fun onTranscodeCanceled() {
|
||||||
Timber.d("Compressing: failure: $failureMessage")
|
|
||||||
job.completeExceptionally(Exception(failureMessage))
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onCancelled() {
|
|
||||||
Timber.d("Compressing: cancel")
|
Timber.d("Compressing: cancel")
|
||||||
job.cancel()
|
job.cancel()
|
||||||
}
|
}
|
||||||
},
|
|
||||||
quality = quality,
|
override fun onTranscodeFailed(exception: Throwable) {
|
||||||
isMinBitRateEnabled = isMinBitRateEnabled,
|
Timber.d("Compressing: failure: ${exception.localizedMessage}")
|
||||||
keepOriginalResolution = keepOriginalResolution
|
job.completeExceptionally(exception)
|
||||||
)
|
}
|
||||||
|
})
|
||||||
|
.transcode()
|
||||||
|
|
||||||
job.join()
|
job.join()
|
||||||
destinationFile
|
destinationFile
|
||||||
|
Loading…
Reference in New Issue
Block a user