Android: 如何使用 android.hardware.camera2 和 MediaRecorder 录制视频

Android: How to record video using android.hardware.camera2 and MediaRecorder

我想使用android.hardware.camera2进行视频录制。我用谷歌搜索但没有得到任何关于此的适当教程。 camera preview 也有一些基于 Camera which is now deprecated. Can anyone help me with latest sample code just for recording video with its preview which can be saved into sd card. I have just check GitHub and Google camera2Video example 的教程,但我需要任何可以集成到我的项目中的简单解决方案。

just for recording video with its preview which can be saved into sd card

如果这就是你想要的,你可以简单地使用:

static final int REQUEST_VIDEO_CAPTURE = 1;

Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
if (takeVideoIntent.resolveActivity(getPackageManager()) != null) {
     startActivityForResult(takeVideoIntent, REQUEST_VIDEO_CAPTURE);
}

Source


如果您想在 camera2 的帮助下自己实现。我建议看一下 googlesamples/android-Camera2Basic

的源代码

特别是 Camera2BasicFragment.java

看看这个开源项目

WesleyElliott/Camera2-Video

有工作代码,而不是 google

的示例