normidar
normidar

Reputation: 579

How can I save the video to MediaStore by CameraX on Java?

I saw this page to learn how to take some video captures and save them to a device.

the Android official code:

// Create MediaStoreOutputOptions for our recorder
val name = "CameraX-recording-" +
        SimpleDateFormat(FILENAME_FORMAT, Locale.US)
                .format(System.currentTimeMillis()) + ".mp4"
val contentValues = ContentValues().apply {
   put(MediaStore.Video.Media.DISPLAY_NAME, name)
}
val mediaStoreOutput = MediaStoreOutputOptions.Builder(this.contentResolver,
                              MediaStore.Video.Media.EXTERNAL_CONTENT_URI)
                              .setContentValues(contentValues)
                              .build()

// 2. Configure Recorder and Start recording to the mediaStoreOutput.
val recording = videoCapture.output
                .prepareRecording(context, mediaStoreOutput)
                .withAudioEnabled()
                .start(ContextCompat.getMainExecutor(this), captureListener)

but I am using Java and I can’t find the output member on Java(if this is a Kotlin keyword, can you tell me what it means?).

I want to save the video that was captured by CameraX but my project is not using Kotlin.

Can somebody translate it to java for me?

thanks!!

Upvotes: 1

Views: 869

Answers (1)

Sergei Kozelko
Sergei Kozelko

Reputation: 833

There are two different VideoCapture classes.

One is in "androidx.camera:camera-core:$version" imported as androidx.camera.core.VideoCapture.

The other one is in "androidx.camera:camera-video:$version" imported as androidx.camera.video.VideoCapture.

Only the second one has the methods you need. And since you are using Java you have to replace output with getOutput().

Upvotes: 1

Related Questions