I want to get uri from CaptureVideo of CameraX
Here is my code for capture video
private void takeVideo() {
if (mso != null) {
if (recording != null) {
recording.close();
recording = null;
return;
}
recording = videoCapture.getOutput().prepareRecording(CameraActivity.this, mso)
.start(ContextCompat.getMainExecutor(this), new Consumer<VideoRecordEvent>() {
@Override
public void accept(VideoRecordEvent videoRecordEvent) {
if (videoRecordEvent instanceof VideoRecordEvent.Start) {
setBackgroundBtn(R.drawable.recoding);
Toast.makeText(CameraActivity.this, "recoding start...", Toast.LENGTH_SHORT).show();
} else if (videoRecordEvent instanceof VideoRecordEvent.Finalize) {
setBackgroundBtn(R.drawable.round_bg);
Toast.makeText(CameraActivity.this, "Recoding stop ...", Toast.LENGTH_SHORT).show();
}
}
});
}
}
The uri should return somewhere on event VideoRecordEvent.Finalize
I debugged recording and show uri when trigger VideoRecordEvent.Finalize
and the uri is in recoding.mRecorder.mOutputUri.uriString
But I have no idea how to get this value because no function to get that uri.
I found answer, I use getOutputResults().getOutputUri()
recording = videoCapture.getOutput().prepareRecording(CameraActivity.this, mso)
.start(ContextCompat.getMainExecutor(this), new Consumer<VideoRecordEvent>() {
@Override
public void accept(VideoRecordEvent videoRecordEvent) {
if (videoRecordEvent instanceof VideoRecordEvent.Start) {
// do something
} else if (videoRecordEvent instanceof VideoRecordEvent.Finalize) {
...
Uri result = ((VideoRecordEvent.Finalize) videoRecordEvent).getOutputResults().getOutputUri();
Toast.makeText(CameraActivity.this, "result url: " + result.toString(), Toast.LENGTH_LONG).show();
Toast.makeText(CameraActivity.this, "Recoding stop ...", Toast.LENGTH_SHORT).show();
}
}
});
Or recordEvent.outputResults.outputUri
CameraX Codelab on event finalize