I created 3D object and I'm also displaying a camera preview. The CameraPreview is
displayed on a SurfaceView definded in the XML file, and the 3D object is displayed on a
framelayout defined in the XML file. I want to display the rotating 3D object over the
CameraPreview, but when I run the App, the CameraPreview is being displayed for few
seconds and after that the activity shows the 3D rotating object independent from the
cameraPreview, I mean, the rotating 3D object is not displayed on the Camerapreview
surface. Is there any way to fix this mistake?
Your help is highlu appreciated.
Code:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mpinfo);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_USER);
surfaceView = (SurfaceView)findViewById(R.id.camerapreview);
surfaceView.setZOrderOnTop(true);
surfaceHolder = surfaceView.getHolder();
surfaceHolder.setFormat(PixelFormat.TRANSPARENT);
surfaceHolder.addCallback(this);
surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width,
int height) {
// TODO Auto-generated method stub
if(previewing){
camera.stopPreview();
previewing = false;
}
if (camera != null){
try {
camera.setPreviewDisplay(surfaceHolder);
camera.startPreview();
previewing = true;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
// TODO Auto-generated method stub
camera = android.hardware.Camera.open();
//Create an Instance with this Activity
glSurface = new GLSurfaceView(this);
//Set our own Renderer
glSurface.setRenderer(new Lesson05());
//Set the GLSurface as View to this Activity
fl01 = (FrameLayout) findViewById(R.id.fl01);
//setContentView(glSurface);
//fl01.addView(cameraSurface);
fl01.addView(glSurface);
}
xml File
<FrameLayout
android:id="@+id/fl01"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</FrameLayout>
<SurfaceView
android:id="@+id/camerapreview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>