Transcoder.transcode() already operated on a background thread
This commit is contained in:
parent
fb42b869dd
commit
efc08b376b
|
@ -31,16 +31,18 @@ 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?): File {
|
progressListener: ProgressListener?): File {
|
||||||
return withContext(Dispatchers.IO) {
|
val destinationFile = withContext(Dispatchers.IO) {
|
||||||
|
createDestinationFile()
|
||||||
|
}
|
||||||
|
|
||||||
val job = Job()
|
val job = Job()
|
||||||
val destinationFile = createDestinationFile()
|
|
||||||
|
|
||||||
Timber.d("Compressing: start")
|
Timber.d("Compressing: start")
|
||||||
progressListener?.onProgress(0, 100)
|
progressListener?.onProgress(0, 100)
|
||||||
|
|
||||||
Transcoder.into(destinationFile.path)
|
Transcoder.into(destinationFile.path)
|
||||||
.addDataSource(videoFile.path)
|
.addDataSource(videoFile.path)
|
||||||
.setListener(object: TranscoderListener {
|
.setListener(object : TranscoderListener {
|
||||||
override fun onTranscodeProgress(progress: Double) {
|
override fun onTranscodeProgress(progress: Double) {
|
||||||
Timber.d("Compressing: $progress%")
|
Timber.d("Compressing: $progress%")
|
||||||
progressListener?.onProgress((progress * 100).toInt(), 100)
|
progressListener?.onProgress((progress * 100).toInt(), 100)
|
||||||
|
@ -65,8 +67,7 @@ internal class VideoCompressor @Inject constructor(private val context: Context)
|
||||||
.transcode()
|
.transcode()
|
||||||
|
|
||||||
job.join()
|
job.join()
|
||||||
destinationFile
|
return destinationFile
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createDestinationFile(): File {
|
private fun createDestinationFile(): File {
|
||||||
|
|
Loading…
Reference in New Issue