minor fixes for media output and toggling resolution
- handle exception when creating media output - if only one resolution is supported, no need to restart the camera
This commit is contained in:
parent
c38bab6824
commit
2627638a76
|
@ -34,7 +34,8 @@ class MediaOutputHelper(
|
|||
private val contentResolver = activity.contentResolver
|
||||
|
||||
fun getImageMediaOutput(): MediaOutput {
|
||||
return if (is3rdPartyIntent) {
|
||||
return try {
|
||||
if (is3rdPartyIntent) {
|
||||
if (outputUri != null) {
|
||||
val outputStream = openOutputStream(outputUri)
|
||||
if (outputStream != null) {
|
||||
|
@ -49,10 +50,15 @@ class MediaOutputHelper(
|
|||
} else {
|
||||
getOutputStreamMediaOutput() ?: getMediaStoreOutput(isPhoto = true)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
errorHandler.showSaveToInternalStorage()
|
||||
getMediaStoreOutput(isPhoto = true)
|
||||
}
|
||||
}
|
||||
|
||||
fun getVideoMediaOutput(): MediaOutput {
|
||||
return if (is3rdPartyIntent) {
|
||||
return try {
|
||||
if (is3rdPartyIntent) {
|
||||
if (outputUri != null) {
|
||||
if (isOreoPlus()) {
|
||||
val fileDescriptor = openFileDescriptor(outputUri)
|
||||
|
@ -81,6 +87,10 @@ class MediaOutputHelper(
|
|||
getFileMediaOutput() ?: getMediaStoreOutput(isPhoto = false)
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
errorHandler.showSaveToInternalStorage()
|
||||
getMediaStoreOutput(isPhoto = false)
|
||||
}
|
||||
}
|
||||
|
||||
private fun getMediaStoreOutput(isPhoto: Boolean): MediaOutput.MediaStoreOutput {
|
||||
|
|
|
@ -373,6 +373,7 @@ class CameraXPreview(
|
|||
}
|
||||
|
||||
private fun toggleResolutions(resolutions: List<ResolutionOption>) {
|
||||
if (resolutions.size >= 2) {
|
||||
val currentIndex = mediaSizeStore.getCurrentSizeIndex(isPhotoCapture, isFrontCameraInUse())
|
||||
|
||||
val nextIndex = if (currentIndex >= resolutions.lastIndex) {
|
||||
|
@ -384,7 +385,7 @@ class CameraXPreview(
|
|||
mediaSizeStore.storeSize(isPhotoCapture, isFrontCameraInUse(), nextIndex)
|
||||
currentRecording?.stop()
|
||||
startCamera()
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
override fun toggleFrontBackCamera() {
|
||||
|
@ -438,7 +439,7 @@ class CameraXPreview(
|
|||
val mediaOutput = mediaOutputHelper.getImageMediaOutput()
|
||||
|
||||
if (mediaOutput is MediaOutput.BitmapOutput) {
|
||||
imageCapture.takePicture(mainExecutor, object : ImageCapture.OnImageCapturedCallback() {
|
||||
imageCapture.takePicture(mainExecutor, object : OnImageCapturedCallback() {
|
||||
override fun onCaptureSuccess(image: ImageProxy) {
|
||||
listener.toggleBottomButtons(false)
|
||||
val bitmap = BitmapUtils.makeBitmap(image.toJpegByteArray())
|
||||
|
@ -457,7 +458,6 @@ class CameraXPreview(
|
|||
val outputOptionsBuilder = when (mediaOutput) {
|
||||
is MediaOutput.MediaStoreOutput -> OutputFileOptions.Builder(contentResolver, mediaOutput.contentUri, mediaOutput.contentValues)
|
||||
is MediaOutput.OutputStreamMediaOutput -> OutputFileOptions.Builder(mediaOutput.outputStream)
|
||||
is MediaOutput.BitmapOutput -> throw IllegalStateException("Cannot produce an OutputFileOptions for a bitmap output")
|
||||
else -> throw IllegalArgumentException("Unexpected option for image ")
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue