mirror of
https://github.com/SimpleMobileTools/Simple-Camera.git
synced 2025-01-05 20:06:51 +01:00
fix getting video quality
This commit is contained in:
parent
7a55969e6d
commit
6c1ccd8db7
@ -1,7 +1,7 @@
|
||||
package com.simplemobiletools.camera.helpers
|
||||
|
||||
import android.util.Log
|
||||
import androidx.camera.core.Camera
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.camera.core.CameraSelector
|
||||
import androidx.camera.lifecycle.ProcessCameraProvider
|
||||
import androidx.camera.video.Quality
|
||||
@ -11,7 +11,10 @@ import com.simplemobiletools.camera.extensions.toVideoQuality
|
||||
import com.simplemobiletools.camera.models.CameraSelectorVideoQualities
|
||||
import com.simplemobiletools.camera.models.VideoQuality
|
||||
|
||||
class VideoQualityManager(private val config: Config) {
|
||||
class VideoQualityManager(
|
||||
private val activity: AppCompatActivity,
|
||||
private val config: Config,
|
||||
) {
|
||||
|
||||
companion object {
|
||||
private const val TAG = "VideoQualityHelper"
|
||||
@ -21,12 +24,11 @@ class VideoQualityManager(private val config: Config) {
|
||||
|
||||
private val videoQualities = mutableListOf<CameraSelectorVideoQualities>()
|
||||
|
||||
fun initSupportedQualities(
|
||||
cameraProvider: ProcessCameraProvider,
|
||||
camera: Camera,
|
||||
) {
|
||||
fun initSupportedQualities(cameraProvider: ProcessCameraProvider) {
|
||||
if (videoQualities.isEmpty()) {
|
||||
for (camSelector in CAMERA_SELECTORS) {
|
||||
cameraProvider.unbindAll()
|
||||
val camera = cameraProvider.bindToLifecycle(activity, camSelector)
|
||||
try {
|
||||
if (cameraProvider.hasCamera(camSelector)) {
|
||||
QualitySelector.getSupportedQualities(camera.cameraInfo)
|
||||
|
@ -58,7 +58,7 @@ class CameraXPreview(
|
||||
private val displayManager = activity.getSystemService(Context.DISPLAY_SERVICE) as DisplayManager
|
||||
private val mediaSoundHelper = MediaSoundHelper()
|
||||
private val windowMetricsCalculator = WindowMetricsCalculator.getOrCreate()
|
||||
private val videoQualityManager = VideoQualityManager(config)
|
||||
private val videoQualityManager = VideoQualityManager(activity, config)
|
||||
private val imageQualityManager = ImageQualityManager(activity)
|
||||
private val exifRemover = ExifRemover(contentResolver)
|
||||
|
||||
@ -110,10 +110,13 @@ class CameraXPreview(
|
||||
private fun startCamera(switching: Boolean = false) {
|
||||
Log.i(TAG, "startCamera: ")
|
||||
imageQualityManager.initSupportedQualities()
|
||||
|
||||
val cameraProviderFuture = ProcessCameraProvider.getInstance(activity)
|
||||
cameraProviderFuture.addListener({
|
||||
try {
|
||||
cameraProvider = cameraProviderFuture.get()
|
||||
val provider = cameraProviderFuture.get()
|
||||
cameraProvider = provider
|
||||
videoQualityManager.initSupportedQualities(provider)
|
||||
bindCameraUseCases()
|
||||
setupCameraObservers()
|
||||
} catch (e: Exception) {
|
||||
@ -143,9 +146,7 @@ class CameraXPreview(
|
||||
cameraSelector,
|
||||
preview,
|
||||
captureUseCase,
|
||||
).also {
|
||||
videoQualityManager.initSupportedQualities(cameraProvider, it)
|
||||
}
|
||||
)
|
||||
|
||||
preview?.setSurfaceProvider(previewView.surfaceProvider)
|
||||
setupZoomAndFocus()
|
||||
@ -188,7 +189,7 @@ class CameraXPreview(
|
||||
}
|
||||
|
||||
private fun buildImageCapture(aspectRatio: Int, rotation: Int): ImageCapture {
|
||||
return ImageCapture.Builder()
|
||||
return Builder()
|
||||
.setCaptureMode(CAPTURE_MODE_MAXIMIZE_QUALITY)
|
||||
.setFlashMode(flashMode)
|
||||
.setJpegQuality(config.photoQuality)
|
||||
@ -362,7 +363,7 @@ class CameraXPreview(
|
||||
if (bitmap != null) {
|
||||
listener.onImageCaptured(bitmap)
|
||||
} else {
|
||||
cameraErrorHandler.handleImageCaptureError(ImageCapture.ERROR_CAPTURE_FAILED)
|
||||
cameraErrorHandler.handleImageCaptureError(ERROR_CAPTURE_FAILED)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user