MediaPlayer-SurfaceView上的Android GLSurfaceView

时间:2012-06-01 18:07:04

标签: android relativelayout surfaceview android-mediaplayer glsurfaceview

我有MediaPlayer使用SurfaceView来显示视频。现在我想在GlSurfaceView上添加MediaPlayerto以在视频上呈现多维数据集。我正在使用相对布局。我可以将两个工作分开,但是我无法将GlSurfaceView放在SurfaceView上。它只是不呈现我用于多维数据集的OpenGL代码。 有人可以帮忙吗?

   _cube = new CubeGLView(this);
   _cube.setEGLConfigChooser(8, 8, 8, 8, 16, 0);
   _cube.setId(10002);
   _cube.getHolder().setFormat(PixelFormat.TRANSLUCENT);
   _cube.getHolder().setFormat(PixelFormat.RGBA_8888);
   //_cube.setRenderMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY);

   _render = new GlRenderer(_cube.getContext());
   _cube.setRenderer(_render);
   _cube.setVisibility(View.GONE);

   RelativeLayout layout = new RelativeLayout(this);
   RelativeLayout.LayoutParams rlp = new RelativeLayout.LayoutParams(
   RelativeLayout.LayoutParams.MATCH_PARENT,
   RelativeLayout.LayoutParams.MATCH_PARENT);

   RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
   RelativeLayout.LayoutParams.WRAP_CONTENT,
   RelativeLayout.LayoutParams.WRAP_CONTENT);
   lp.addRule(RelativeLayout.CENTER_IN_PARENT);

   mPreview.setLayoutParams(lp);
   _cube.setLayoutParams(lp);

   layout.addView(_cube);
   layout.addView(mPreview);

   setContentView(layout, rlp);

1 个答案:

答案 0 :(得分:2)

解决它: mPreview = new SurfaceView(this);         mPreview.setId(10001);

    mPreview.setOnClickListener(this);
    mPreview.setClickable(true);

    holder = mPreview.getHolder();
    holder.addCallback(this);
    holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    extras = getIntent().getExtras();


    _cube = new CubeGLView(this);
    _cube.setEGLConfigChooser(8, 8, 8, 8, 16, 0);

    _cube.setId(10002);
    _cube.getHolder().setFormat(PixelFormat.TRANSLUCENT);
    _cube.getHolder().setFormat(PixelFormat.RGBA_8888);


    _render = new GlRenderer(_cube.getContext());
    _cube.setRenderer(_render);



    RelativeLayout layout = new RelativeLayout(this);
    RelativeLayout.LayoutParams rlp = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.MATCH_PARENT,
            RelativeLayout.LayoutParams.MATCH_PARENT);

    RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.MATCH_PARENT,
            RelativeLayout.LayoutParams.MATCH_PARENT);
    lp.addRule(RelativeLayout.CENTER_IN_PARENT);

    mPreview.setLayoutParams(lp);

    LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    params.setMargins(100,10, 0,0);
    _cube.setLayoutParams(params);

    DataManager datamanager = DataManager.getInstance();

    if (!datamanager.isHasalreadyview()){
        Log.d(TAG, "onCreate icicle == null");
        layout.addView(_cube);
        layout.addView(mPreview);
        datamanager.setHasalreadyview(true);
    }else{
        Log.d(TAG, "onCreate icicle != null");
        layout.addView(mPreview);
        layout.addView(_cube);
    }


    setContentView(layout, rlp);