简体   繁体   中英

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

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() .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM