[英]How can I save the video to MediaStore by CameraX on Java?
我看到這個頁面是為了學習如何拍攝一些視頻並將它們保存到設備中。
Android官方代碼:
// 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)
但我正在使用 Java 並且在 Java 上找不到output
成員(如果這是 Kotlin 關鍵字,你能告訴我它是什么意思嗎?)。
我想保存由CameraX
捕獲的視頻,但我的項目沒有使用 Kotlin。
有人可以幫我翻譯成 java 嗎?
謝謝
有兩個不同的VideoCapture
類。
一個是在"androidx.camera:camera-core:$version"
中導入為androidx.camera.core.VideoCapture
。
另一個是在"androidx.camera:camera-video:$version"
中導入為androidx.camera.video.VideoCapture
。
只有第二個有你需要的方法。 並且由於您使用的是 Java ,因此您必須將output
替換為getOutput()
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.