show a video resolution picker if recording fails

This commit is contained in:
tibbi
2018-07-10 11:56:05 +02:00
parent 63d228a50e
commit 7e709bebfb
24 changed files with 51 additions and 14 deletions

View File

@ -13,7 +13,7 @@ import com.simplemobiletools.commons.models.RadioItem
import kotlinx.android.synthetic.main.dialog_change_resolution.view.*
class ChangeResolutionDialog(val activity: SimpleActivity, val isFrontCamera: Boolean, val photoResolutions: ArrayList<MySize>,
val videoResolutions: ArrayList<MySize>, val callback: () -> Unit) {
val videoResolutions: ArrayList<MySize>, val openVideoResolutions: Boolean, val callback: () -> Unit) {
private var dialog: AlertDialog
private val config = activity.config
@ -27,7 +27,11 @@ class ChangeResolutionDialog(val activity: SimpleActivity, val isFrontCamera: Bo
.setPositiveButton(R.string.ok, null)
.setOnDismissListener { callback() }
.create().apply {
activity.setupDialogStuff(view, this, if (isFrontCamera) R.string.front_camera else R.string.back_camera)
activity.setupDialogStuff(view, this, if (isFrontCamera) R.string.front_camera else R.string.back_camera) {
if (openVideoResolutions) {
view.change_resolution_video_holder.performClick()
}
}
}
}

View File

@ -500,7 +500,7 @@ class PreviewCameraOne : ViewGroup, SurfaceHolder.Callback, MyPreview {
val photoResolutions = mCamera!!.parameters.supportedPictureSizes.map { MySize(it.width, it.height) } as ArrayList<MySize>
val videoSizes = mCamera!!.parameters.supportedVideoSizes ?: mCamera!!.parameters.supportedPreviewSizes
val videoResolutions = videoSizes.map { MySize(it.width, it.height) } as ArrayList<MySize>
ChangeResolutionDialog(mActivity!!, getIsUsingFrontCamera(), photoResolutions, videoResolutions) {
ChangeResolutionDialog(mActivity!!, getIsUsingFrontCamera(), photoResolutions, videoResolutions, false) {
if (oldResolution != getSelectedResolution()) {
refreshPreview()
}

View File

@ -25,6 +25,8 @@ import android.view.MotionEvent
import android.view.Surface
import android.view.TextureView
import android.view.ViewGroup
import android.widget.Toast
import com.simplemobiletools.camera.R
import com.simplemobiletools.camera.activities.MainActivity
import com.simplemobiletools.camera.dialogs.ChangeResolutionDialog
import com.simplemobiletools.camera.extensions.config
@ -36,6 +38,7 @@ import com.simplemobiletools.camera.models.FocusArea
import com.simplemobiletools.camera.models.MySize
import com.simplemobiletools.commons.extensions.rescanPaths
import com.simplemobiletools.commons.extensions.showErrorToast
import com.simplemobiletools.commons.extensions.toast
import com.simplemobiletools.commons.helpers.isJellyBean1Plus
import java.io.File
import java.lang.IllegalArgumentException
@ -899,17 +902,22 @@ class PreviewCameraTwo : ViewGroup, TextureView.SurfaceTextureListener, MyPrevie
}
mIsRecording = false
mMediaRecorder!!.stop()
mMediaRecorder!!.reset()
mActivity.rescanPaths(arrayListOf(mLastVideoPath)) {
mActivity.videoSaved(Uri.fromFile(File(mLastVideoPath)))
try {
mMediaRecorder!!.stop()
mMediaRecorder!!.reset()
mActivity.rescanPaths(arrayListOf(mLastVideoPath)) {
mActivity.videoSaved(Uri.fromFile(File(mLastVideoPath)))
}
} catch (e: Exception) {
mActivity.toast(R.string.video_recording_failed, Toast.LENGTH_LONG)
openResolutionsDialog(true)
} finally {
Thread {
closeCamera()
openCamera(mTextureView.width, mTextureView.height)
}.start()
mActivity.setRecordingState(false)
}
Thread {
closeCamera()
openCamera(mTextureView.width, mTextureView.height)
}.start()
mActivity.setRecordingState(false)
}
private fun getAvailableVideoSizes(configMap: StreamConfigurationMap) = configMap.getOutputSizes(MediaRecorder::class.java).filter {
@ -934,11 +942,15 @@ class PreviewCameraTwo : ViewGroup, TextureView.SurfaceTextureListener, MyPrevie
override fun getCameraState() = mCameraState
override fun showChangeResolutionDialog() {
openResolutionsDialog(false)
}
private fun openResolutionsDialog(openVideoResolutions: Boolean) {
val oldResolution = getCurrentResolution()
val configMap = getCameraCharacteristics().get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP)
val photoResolutions = configMap.getOutputSizes(ImageFormat.JPEG).map { MySize(it.width, it.height) } as ArrayList
val videoResolutions = getAvailableVideoSizes(configMap).map { MySize(it.width, it.height) } as ArrayList
ChangeResolutionDialog(mActivity, mUseFrontCamera, photoResolutions, videoResolutions) {
ChangeResolutionDialog(mActivity, mUseFrontCamera, photoResolutions, videoResolutions, openVideoResolutions) {
if (oldResolution != getCurrentResolution()) {
if (mIsRecording) {
stopRecording()