I need two camera previews in my app. However, android camera can give only one preview at a time. Is there any way to pipeline/copy that preview to another view? I came across this question How to create multi lenses or preview using one camera in Android and he says that
On Android 3.0 or later, you can use the setPreviewTexture method to pipe the preview data into an OpenGL texture, which you can then render to multiple quads in a GLSurfaceView or equivalent.
But I have no idea how to render that to multiple quads in GLSurfaceView
.I need to support android 4.0+. But I don't want to use preview frame from preview callback. It causes significant delay. Any help would be appreciated. Thanks!!
Here is my code for single preview
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/black"
tools:context=".MainActivity" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="10" >
<TextureView
android:id="@+id/textureView1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="5" />
<TextureView
android:id="@+id/textureView2"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="5" />
</LinearLayout>
</RelativeLayout>
MainActivity.java
public class MainActivity extends Activity implements SurfaceTextureListener{
private Camera mCamera;
private TextureView mTextureView1;
private TextureView mTextureView2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mTextureView1 = (TextureView) findViewById(R.id.textureView1);
mTextureView2 = (TextureView) findViewById(R.id.textureView2);
mTextureView1.setSurfaceTextureListener(this);
}
@Override
public void onSurfaceTextureAvailable(SurfaceTexture surface, int width,
int height) {
try {
mCamera = Camera.open(getCameraId());
mCamera.setPreviewTexture(surface);
CameraInfo cameraInfo = new CameraInfo();
Camera.getCameraInfo(getCameraId(), cameraInfo);
setCameraDisplayOrientation(this, getCameraId(), mCamera);
mCamera.startPreview();
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
try {
mCamera.stopPreview();
mCamera.release();
} catch (Exception e) {
e.printStackTrace();
}
return true;
}
@Override
public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width,
int height) {
}
@Override
public void onSurfaceTextureUpdated(SurfaceTexture surface) {
}
}
Output: