Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to record the video using camera preview on TextureView

I have been playing with TextureView on some Android 4.0 devices. For example, I tried to develop a simple app, which can record the video and uses TextureView for its preview. However, as far as I read the Android API documents, standard MediaRecorder requires certain surface in order to perform video recording, but on the other hand, TextureView does not have its own surface anymore, so an incompatibility between TextureView and MediaRecorder seems exist.

MediaRecorder.setPreviewDisplay

TextureView

Does anyone know how to record video using standard MediaRecorder with TextureView as its camera preview? Or is there any way to record video other than MediaRecorder?

Thank you very much.

like image 755
mylovepenguins Avatar asked Mar 20 '12 17:03

mylovepenguins


People also ask

What is preview in camera?

The image is cropped to the aspect ratio of the camera preview, then scaled to fill the preview (field of view is reduced): On foldable devices, the orientation of the camera sensor can be portrait while the aspect ratio of the display is landscape: Figure 10.

What is TextureView?

If you want to display a live video stream or any content stream such as video or an OpenGL scene, you can use TextureView provided by android in order to do that. In order to use TextureView, all you need to do is get its SurfaceTexture.The SurfaceTexture can then be used to render content.


1 Answers

According to this issue, on Jelly Bean and higher, you simply don't call setPreviewDisplay(), and MediaRecorder will automatically use the preview used by the Camera. I can confirm that not calling setPreviewDisplay() does indeed work, at least on Android 4.2, when the Camera preview is set to be a TextureView. I have not yet tried this on older Android versions to confirm that 4.1 works.

This does leave a bit of a gap, in that Android 3.0-4.0 devices perhaps cannot use TextureView for previews.

like image 186
CommonsWare Avatar answered Oct 12 '22 01:10

CommonsWare