Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to start video recording. #236

Open
krghv85 opened this issue Jul 9, 2022 · 1 comment
Open

Unable to start video recording. #236

krghv85 opened this issue Jul 9, 2022 · 1 comment

Comments

@krghv85
Copy link

krghv85 commented Jul 9, 2022

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
    }
}
@deadman00069
Copy link

i have also same issue, its not starting video recording

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants