googlearchive/android-Camera2Video

Auto record on start

Closed this issue · 2 comments

How can I set the application to auto start recording?

I have tried to insert these lines inside the fragment onViewCreated but without success:
mIsRecordingVideo = true;
or startRecordingVideo();

Can someone help?
Thanks in advance

I could make my app with auto recording. What I've done was to write the whole code inside the activity instead of using Fragment. And here is my code to enable auto recording:

`
private CameraDevice.StateCallback mStateCallback = new CameraDevice.StateCallback() {

    @Override
    public void onOpened(@NonNull CameraDevice cameraDevice) {
        mCameraDevice = cameraDevice;
        startPreview();
        mCameraOpenCloseLock.release();
        if (null != mTextureView) {
            configureTransform(mTextureView.getWidth(), mTextureView.getHeight());
        }

        // auto record
        if (mIsRecordingVideo) {
            try {
                createVideoFileName();
            } catch (IOException e) {
                e.printStackTrace();
            }

            startRecordingVideo();
            mMediaRecorder.start();
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    countDownTimer.start();
                }
            });
        }
    }

    @Override
    public void onDisconnected(@NonNull CameraDevice cameraDevice) {
        mCameraOpenCloseLock.release();
        cameraDevice.close();
        mCameraDevice = null;
    }

    @Override
    public void onError(@NonNull CameraDevice cameraDevice, int error) {
        mCameraOpenCloseLock.release();
        cameraDevice.close();
        mCameraDevice = null;
        finish();
    }

};`

This sample has been migrated to a new location where we can accept Pull Requests (check README for more information).

As recommended by GitHub, we are closing all issues and pull requests now that this older repo will be archived.

If you still see this issue in the updated repo, please reopen the issue/PR there. Thank you!