added skipping of media compressor when quality is UNCOMPRESSED
added media compressor logging
This commit is contained in:
@@ -105,7 +105,9 @@ fun NewMediaView(
|
|||||||
|
|
||||||
var showRelaysDialog by remember { mutableStateOf(false) }
|
var showRelaysDialog by remember { mutableStateOf(false) }
|
||||||
var relayList = remember { accountViewModel.account.activeWriteRelays().toImmutableList() }
|
var relayList = remember { accountViewModel.account.activeWriteRelays().toImmutableList() }
|
||||||
var mediaQualitySlider by remember { mutableIntStateOf(1) } // 0 = Low, 1 = Medium, 2 = High
|
|
||||||
|
// 0 = Low, 1 = Medium, 2 = High, 3=UNCOMPRESSED
|
||||||
|
var mediaQualitySlider by remember { mutableIntStateOf(1) }
|
||||||
|
|
||||||
Dialog(
|
Dialog(
|
||||||
onDismissRequest = { onClose() },
|
onDismissRequest = { onClose() },
|
||||||
@@ -225,6 +227,7 @@ fun NewMediaView(
|
|||||||
0 -> stringRes(R.string.media_compression_quality_low)
|
0 -> stringRes(R.string.media_compression_quality_low)
|
||||||
1 -> stringRes(R.string.media_compression_quality_medium)
|
1 -> stringRes(R.string.media_compression_quality_medium)
|
||||||
2 -> stringRes(R.string.media_compression_quality_high)
|
2 -> stringRes(R.string.media_compression_quality_high)
|
||||||
|
3 -> "UNCOMPRESSED"
|
||||||
else -> stringRes(R.string.media_compression_quality_medium)
|
else -> stringRes(R.string.media_compression_quality_medium)
|
||||||
},
|
},
|
||||||
modifier = Modifier.align(Alignment.Center),
|
modifier = Modifier.align(Alignment.Center),
|
||||||
@@ -234,8 +237,8 @@ fun NewMediaView(
|
|||||||
Slider(
|
Slider(
|
||||||
value = mediaQualitySlider.toFloat(),
|
value = mediaQualitySlider.toFloat(),
|
||||||
onValueChange = { mediaQualitySlider = it.toInt() },
|
onValueChange = { mediaQualitySlider = it.toInt() },
|
||||||
valueRange = 0f..2f,
|
valueRange = 0f..3f,
|
||||||
steps = 1,
|
steps = 2,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1735,7 +1735,9 @@ fun ImageVideoDescription(
|
|||||||
}
|
}
|
||||||
var message by remember { mutableStateOf("") }
|
var message by remember { mutableStateOf("") }
|
||||||
var sensitiveContent by remember { mutableStateOf(false) }
|
var sensitiveContent by remember { mutableStateOf(false) }
|
||||||
var mediaQualitySlider by remember { mutableIntStateOf(1) } // 0 = Low, 1 = Medium, 2 = High
|
|
||||||
|
// 0 = Low, 1 = Medium, 2 = High, 3=UNCOMPRESSED
|
||||||
|
var mediaQualitySlider by remember { mutableIntStateOf(1) }
|
||||||
|
|
||||||
Column(
|
Column(
|
||||||
modifier =
|
modifier =
|
||||||
@@ -1953,6 +1955,7 @@ fun ImageVideoDescription(
|
|||||||
0 -> stringRes(R.string.media_compression_quality_low)
|
0 -> stringRes(R.string.media_compression_quality_low)
|
||||||
1 -> stringRes(R.string.media_compression_quality_medium)
|
1 -> stringRes(R.string.media_compression_quality_medium)
|
||||||
2 -> stringRes(R.string.media_compression_quality_high)
|
2 -> stringRes(R.string.media_compression_quality_high)
|
||||||
|
3 -> "UNCOMPRESSED"
|
||||||
else -> stringRes(R.string.media_compression_quality_medium)
|
else -> stringRes(R.string.media_compression_quality_medium)
|
||||||
},
|
},
|
||||||
modifier = Modifier.align(Alignment.Center),
|
modifier = Modifier.align(Alignment.Center),
|
||||||
@@ -1962,8 +1965,8 @@ fun ImageVideoDescription(
|
|||||||
Slider(
|
Slider(
|
||||||
value = mediaQualitySlider.toFloat(),
|
value = mediaQualitySlider.toFloat(),
|
||||||
onValueChange = { mediaQualitySlider = it.toInt() },
|
onValueChange = { mediaQualitySlider = it.toInt() },
|
||||||
valueRange = 0f..2f,
|
valueRange = 0f..3f,
|
||||||
steps = 1,
|
steps = 2,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ class MediaCompressor {
|
|||||||
onError: (Int) -> Unit,
|
onError: (Int) -> Unit,
|
||||||
mediaQuality: CompressorQuality,
|
mediaQuality: CompressorQuality,
|
||||||
) {
|
) {
|
||||||
|
if (mediaQuality != CompressorQuality.UNCOMPRESSED) {
|
||||||
checkNotInMainThread()
|
checkNotInMainThread()
|
||||||
|
|
||||||
if (contentType?.startsWith("video", true) == true) {
|
if (contentType?.startsWith("video", true) == true) {
|
||||||
@@ -59,6 +60,7 @@ class MediaCompressor {
|
|||||||
CompressorQuality.MEDIUM -> VideoQuality.MEDIUM
|
CompressorQuality.MEDIUM -> VideoQuality.MEDIUM
|
||||||
CompressorQuality.HIGH -> VideoQuality.HIGH
|
CompressorQuality.HIGH -> VideoQuality.HIGH
|
||||||
CompressorQuality.VERY_HIGH -> VideoQuality.VERY_HIGH
|
CompressorQuality.VERY_HIGH -> VideoQuality.VERY_HIGH
|
||||||
|
else -> VideoQuality.MEDIUM // dodgy
|
||||||
}
|
}
|
||||||
Log.d("MediaCompressor", "Using video compression $mediaQuality")
|
Log.d("MediaCompressor", "Using video compression $mediaQuality")
|
||||||
VideoCompressor.start(
|
VideoCompressor.start(
|
||||||
@@ -85,7 +87,8 @@ class MediaCompressor {
|
|||||||
override fun onProgress(
|
override fun onProgress(
|
||||||
index: Int,
|
index: Int,
|
||||||
percent: Float,
|
percent: Float,
|
||||||
) {}
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
override fun onStart(index: Int) {
|
override fun onStart(index: Int) {
|
||||||
// Compression start
|
// Compression start
|
||||||
@@ -97,8 +100,10 @@ class MediaCompressor {
|
|||||||
path: String?,
|
path: String?,
|
||||||
) {
|
) {
|
||||||
if (path != null) {
|
if (path != null) {
|
||||||
|
Log.d("MediaCompressor", "Video compression success. Compressed size [$size]")
|
||||||
onReady(Uri.fromFile(File(path)), contentType, size)
|
onReady(Uri.fromFile(File(path)), contentType, size)
|
||||||
} else {
|
} else {
|
||||||
|
Log.d("MediaCompressor", "Video compression successful, but returned null path")
|
||||||
onError(R.string.compression_returned_null)
|
onError(R.string.compression_returned_null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -108,6 +113,7 @@ class MediaCompressor {
|
|||||||
failureMessage: String,
|
failureMessage: String,
|
||||||
) {
|
) {
|
||||||
// keeps going with original video
|
// keeps going with original video
|
||||||
|
Log.d("MediaCompressor", "Video compression failed: $failureMessage")
|
||||||
onReady(uri, contentType, null)
|
onReady(uri, contentType, null)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,15 +134,19 @@ class MediaCompressor {
|
|||||||
CompressorQuality.MEDIUM -> 60
|
CompressorQuality.MEDIUM -> 60
|
||||||
CompressorQuality.HIGH -> 80
|
CompressorQuality.HIGH -> 80
|
||||||
CompressorQuality.VERY_HIGH -> 90
|
CompressorQuality.VERY_HIGH -> 90
|
||||||
|
else -> 60
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Log.d("MediaCompressor", "Using image compression $mediaQuality")
|
Log.d("MediaCompressor", "Using image compression $mediaQuality")
|
||||||
|
val tempFile = from(uri, contentType, applicationContext)
|
||||||
val compressedImageFile =
|
val compressedImageFile =
|
||||||
Compressor.compress(applicationContext, from(uri, contentType, applicationContext)) {
|
Compressor.compress(applicationContext, tempFile) {
|
||||||
default(width = 640, format = Bitmap.CompressFormat.JPEG, quality = imageQuality)
|
default(width = 640, format = Bitmap.CompressFormat.JPEG, quality = imageQuality)
|
||||||
}
|
}
|
||||||
|
Log.d("MediaCompressor", "Image compression success. Original size [${tempFile.length()}], new size [${compressedImageFile.length()}]")
|
||||||
onReady(compressedImageFile.toUri(), contentType, compressedImageFile.length())
|
onReady(compressedImageFile.toUri(), contentType, compressedImageFile.length())
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
|
Log.d("MediaCompressor", "Image compression failed: ${e.message}")
|
||||||
if (e is CancellationException) throw e
|
if (e is CancellationException) throw e
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
onReady(uri, contentType, null)
|
onReady(uri, contentType, null)
|
||||||
@@ -144,6 +154,10 @@ class MediaCompressor {
|
|||||||
} else {
|
} else {
|
||||||
onReady(uri, contentType, null)
|
onReady(uri, contentType, null)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
Log.d("MediaCompressor", "UNCOMPRESSED quality selected, skip compression and continue with original media.")
|
||||||
|
onReady(uri, contentType, null)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun from(
|
fun from(
|
||||||
@@ -188,6 +202,7 @@ class MediaCompressor {
|
|||||||
0 -> CompressorQuality.LOW
|
0 -> CompressorQuality.LOW
|
||||||
1 -> CompressorQuality.MEDIUM
|
1 -> CompressorQuality.MEDIUM
|
||||||
2 -> CompressorQuality.HIGH
|
2 -> CompressorQuality.HIGH
|
||||||
|
3 -> CompressorQuality.UNCOMPRESSED
|
||||||
else -> CompressorQuality.MEDIUM
|
else -> CompressorQuality.MEDIUM
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -196,6 +211,7 @@ class MediaCompressor {
|
|||||||
CompressorQuality.LOW -> 0
|
CompressorQuality.LOW -> 0
|
||||||
CompressorQuality.MEDIUM -> 1
|
CompressorQuality.MEDIUM -> 1
|
||||||
CompressorQuality.HIGH -> 2
|
CompressorQuality.HIGH -> 2
|
||||||
|
CompressorQuality.UNCOMPRESSED -> 3
|
||||||
else -> 1
|
else -> 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -206,4 +222,5 @@ enum class CompressorQuality {
|
|||||||
MEDIUM,
|
MEDIUM,
|
||||||
HIGH,
|
HIGH,
|
||||||
VERY_HIGH,
|
VERY_HIGH,
|
||||||
|
UNCOMPRESSED,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user