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

CameraX: NullPointerException when trying to record video #50

Closed
Twometer opened this issue Aug 9, 2019 · 8 comments
Closed

CameraX: NullPointerException when trying to record video #50

Twometer opened this issue Aug 9, 2019 · 8 comments

Comments

@Twometer
Copy link

Twometer commented Aug 9, 2019

I have a simple video recording app set up like this:

VideoCaptureConfig videoCaptureConfig = new VideoCaptureConfig.Builder()
        .setLensFacing(CameraX.LensFacing.BACK)
        .setTargetAspectRatio(new Rational(16, 9))
        .setTargetRotation(viewFinder.getDisplay().getRotation())
        .build();
videoCapture = new VideoCapture(videoCaptureConfig);

CameraX.bindToLifecycle(this, preview, videoCapture);

...

 videoCapture.startRecording(file, new VideoCapture.OnVideoSavedListener() { ... });

which leads to the following NullPointerException:

    java.lang.NullPointerException: Attempt to invoke virtual method 'void android.media.AudioRecord.startRecording()' on a null object reference
        at androidx.camera.core.VideoCapture.startRecording(VideoCapture.java:262)
        at androidx.camera.core.VideoCapture.startRecording(VideoCapture.java:236)
        at de.twometer.stream.cam.CameraActivity.lambda$onCreate$1$CameraActivity(CameraActivity.java:77)
        at de.twometer.stream.cam.-$$Lambda$CameraActivity$MvEAnqH_74mMgbMAcSbB_pNoJ3k.onClick(Unknown Source:4)
        at android.view.View.performClick(View.java:7352)
        at android.view.View.performClickInternal(View.java:7318)
        at android.view.View.access$3200(View.java:846)
        at android.view.View$PerformClick.run(View.java:27807)
        at android.os.Handler.handleCallback(Handler.java:873)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7037)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:965)

I am using CameraX version 1.0.0-alpha04

@Twometer
Copy link
Author

Twometer commented Aug 9, 2019

Nevermind, I am just stupid and forgot to request audio permission.

@Twometer Twometer closed this as completed Aug 9, 2019
@jaydeepw
Copy link

jaydeepw commented May 26, 2021

I have RECORD_AUDIO permission however, I am still getting this exception when trying to capture the video while using latest 1.1.0-alpha04 CameraX dependencies.

@ssjsaha
Copy link

ssjsaha commented Jul 6, 2021

Hi there , Did you guys had the solution? Im facing the same problem here !

@Balasnest
Copy link

Balasnest commented Oct 16, 2021

Facing the same. It's happening in the release build. Debug build is fine.

----- solution:
Yeah. microphone permission is required. Is there a way to record without audio?

@chief10x
Copy link

I still face the same issue

@temcguir
Copy link

androidx.camera.core.VideoCapture is not a supported public API, and should give lint errors when you try to use it as it is marked as restricted.

androidx.camera.video.VideoCapture, which is part of the camera-video artifact is the officially supported use case for recording video. Are you running into this problem with that class?

@namdhis
Copy link

namdhis commented Sep 23, 2022

Hi there , Did you guys had the solution? Im facing the same problem here !

Did you find the way to record video by camera X without using audio permision yet?

@temcguir
Copy link

androidx.camera.video.VideoCapture should not require the audio permission unless you call PendingRecording.withAudioEnabled().

Please see this guide on how to use the new VideoCapture API.

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

7 participants