-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Compressed video stores in internal app dir at now.
- Loading branch information
Showing
3 changed files
with
77 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
app/src/main/java/com/desiredsoftware/socialquiz/utils/VideoCompressor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.desiredsoftware.socialquiz.utils | ||
|
||
import android.content.Context | ||
import android.util.Log | ||
import com.iceteck.silicompressorr.SiliCompressor | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.withContext | ||
import java.io.File | ||
|
||
class VideoCompressor constructor( | ||
val context: Context | ||
) { | ||
suspend fun compressVideo(videoUriString: String, destinationDirectory: String): String? { | ||
var compressedFilePath : String? = null | ||
Log.d("compressVideo", "compressVideo start") | ||
withContext(Dispatchers.IO) { | ||
try { | ||
val f: File = context.getDir(destinationDirectory, Context.MODE_PRIVATE) | ||
if (f.mkdirs() || f.isDirectory){ | ||
compressedFilePath = SiliCompressor.with(context) | ||
.compressVideo(videoUriString, f.absolutePath) | ||
} | ||
else{ | ||
Log.e("compressVideo", "compressVideo error: can't create dir") | ||
} | ||
|
||
} catch (e: Exception) { | ||
Log.e("compressVideo", "compressVideo error: ${e.message}, cause: ${e.cause}") | ||
} | ||
} | ||
Log.d("compressVideo", "compressVideo after await: compressedFilePath=$compressedFilePath") | ||
return compressedFilePath | ||
} | ||
} |