Skip to content

Unable to start video recording. #236

Description

@krghv85

Hi,
I am getting following exception while start camera. and my goal is to capture video and continues frames.

Please help me to solve this issue.

com.priyankvasa.android.cameraviewex.CameraViewException: Unable to start video recording.
java.lang.ArithmeticException: divide by zero
Unable to start video recording.

My code is --

<com.priyankvasa.android.cameraviewex.CameraView
    android:id="@+id/camera"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:adjustViewBounds="true"
    android:keepScreenOn="true"
    app:aspectRatio="4:3"
    app:autoFocus="continuous_video"
    app:awb="auto"
    app:cameraMode="continuous_frame|video_capture"
    app:continuousFrameSize="W1440,1080"
    app:facing="back"
    app:flash="off"
    app:jpegQuality="high"
    app:noiseReduction="high_quality"
    app:opticalStabilization="true"
    app:outputFormat="jpeg"
    app:pinchToZoom="false"
    app:shutter="short_time"
    app:singleCaptureSize="1920,H1080"
    app:touchToFocus="false"
    app:zsl="true" />

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

    // Callbacks on UI thread
    _binding?.camera?.addCameraOpenedListener { /* Camera opened. */ }
        ?.addCameraErrorListener { t: Throwable, errorLevel: ErrorLevel -> /* Camera error! */
            Log.d("AAAAAA  ", "addCameraErrorListener")
        }
        ?.addCameraClosedListener { /* Camera closed. */
            Log.d("AAAAAA  ", "addCameraClosedListener")
        }

}

override fun onResume() {
    super.onResume()
    if (ActivityCompat.checkSelfPermission(
            requireContext(),
            Manifest.permission.CAMERA
        ) != PackageManager.PERMISSION_GRANTED
    ) {
        // TODO: Consider calling
        //    ActivityCompat#requestPermissions
        // here to request the missing permissions, and then overriding
        //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
        //                                          int[] grantResults)
        // to handle the case where the user grants the permission. See the documentation
        // for ActivityCompat#requestPermissions for more details.
        return
    }
    _binding?.camera?.start(Modes.DEFAULT_CAMERA_ID)

// _binding?.camera?.setCameraMode(Modes.CameraMode.SINGLE_CAPTURE or Modes.CameraMode.CONTINUOUS_FRAME or Modes.CameraMode.VIDEO_CAPTURE)
// _binding?.camera?.setCameraMode(Modes.CameraMode.VIDEO_CAPTURE)

// OR keep other modes as is and enable video capture mode
// _binding?.camera?.enableCameraMode(Modes.CameraMode.VIDEO_CAPTURE)

// Callback on UI thread
_binding?.camera?.addVideoRecordStartedListener { /* Video recording started */
Log.d("AAAAAA ", "Video recording started")
}

// Callback on UI thread
_binding?.camera?.addVideoRecordStoppedListener { isSuccess ->
// Video recording stopped
Log.d("AAAAAA ", "Video recording stopped")
// isSuccess is true if video was recorded and saved successfully
}

    _binding?.camera?.setContinuousFrameListener {
        Log.d("AAAAAA  ", "Continuous Frame Listener")
        showFramePreview(it)
    }

    val direct = File(Environment.getExternalStorageDirectory().toString() + "/capture_video")
    if (!direct.exists()) {
        val wallpaperDirectory = File("/sdcard/capture_video/")
        wallpaperDirectory.mkdirs()
    }
    val file = File("/sdcard/capture_video/", "video_" + System.currentTimeMillis() + ".mp4")
    if (file.exists()) {
        file.delete()
    }

    _binding?.camera?.startVideoRecording(file) {
        // Configure video (MediaRecorder) parameters
        audioEncoder = AudioEncoder.Aac
        videoFrameRate = 30
        videoStabilization = true
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions