1

in my application i want play 3Dvideo on target image, i have started camera in c++ and able to set 3D image on target image using custom view, now my requirement is play 3Dvideo on target image in place of 3D image, i have tried to play video using custom GLSurfaceView. below is my code but onSurfaceCreated method is not called.

public class GLPreview extends GLSurfaceView implements
    OnBufferingUpdateListener, OnCompletionListener, OnPreparedListener,
    OnVideoSizeChangedListener, SurfaceHolder.Callback,
    GLSurfaceView.Renderer{

    private static final String TAG = "MediaPlayerDemo";
    private int mVideoWidth;
    private int mVideoHeight;
    private MediaPlayer mMediaPlayer;
    private GLSurfaceView mPreview;
    private SurfaceHolder holder;
    private String path;
    private Bundle extras;
    private static final String MEDIA = "media";
    private static final int LOCAL_VIDEO = 4;
    private static final int STREAM_VIDEO = 5;
    private boolean mIsVideoSizeKnown = false;
    private boolean mIsVideoReadyToBePlayed = false;
    Context context2;

    public GLPreview(Context context, AttributeSet attrs) {
        super(context, attrs);
        // this.setZOrderMediaOverlay(true);
        Log.d(TAG, "GLPreview: OnPause");
        this.context2 = context;

        mPreview = (GLSurfaceView) findViewById(R.id.surface);
        // holder = mPreview.getHolder();
        setBackgroundResource(R.drawable.vuforiasizzlereel);
    }

    public void playVideo() {
        doCleanUp();
        try {

            // Create a new media player and set the listeners
            mMediaPlayer = new MediaPlayer();
                mMediaPlayer.setDataSource(path);           
            mMediaPlayer.setDisplay(holder);
            mMediaPlayer.prepare();
            mMediaPlayer.setOnBufferingUpdateListener(this);
            mMediaPlayer.setOnCompletionListener(this);
            mMediaPlayer.setOnPreparedListener(this);
            mMediaPlayer.setOnVideoSizeChangedListener(this);
            mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);

        } catch (Exception e) {
            Log.e(TAG, "error: " + e.getMessage(), e);
        }
    }
    public void onPause() {
        super.onPause();
        Log.d(TAG, "GLPreview: OnPause");
    }

    public void onResume() {
        // this.setZOrderMediaOverlay(true);
        super.onResume();
        Log.d(TAG, "GLPreview: OnResume");
    }
    public void surfaceCreated(SurfaceHolder holder) {
        Log.d(TAG, "GLPreview: surfaceCreated");
        super.surfaceCreated(holder);
    }
    public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
        Log.d(TAG, String.format(
                "GLPreview: surfaceChanged, format=%d, w=%d, h=%d", format, w,
                h));
        super.surfaceChanged(holder, format, w, h);
    }
    public void surfaceDestroyed(SurfaceHolder holder) {
        Log.d(TAG, "GLPreview: surfaceDestroyed");
        super.surfaceDestroyed(holder);
    }
    protected void onAttachedToWindow() {
        Log.d(TAG, "GLPreview: onAttachedToWindow");
        super.onAttachedToWindow();
    }
    protected void onDetachedFromWindow() {
        Log.d(TAG, "GLPreview: onDetachedFromWindow");
        super.onDetachedFromWindow();
    }
    protected void onWindowVisibilityChanged(int vis) {
        String newVisibility;
        switch (vis) {
        case View.GONE:
            newVisibility = "GONE";
            break;
        case View.INVISIBLE:
            newVisibility = "INVISIBLE";
            break;
        case View.VISIBLE:
            newVisibility = "VISIBLE";
            break;
        default:
            newVisibility = String.format("Unknown constant %d", vis);
        }

        Log.d(TAG, String.format("GLPreview: onWindowVisibilityChanged -> %s",
                newVisibility));
        super.onWindowVisibilityChanged(vis);
    }
    private void doCleanUp() {
        mVideoWidth = 0;
        mVideoHeight = 0;
        mIsVideoReadyToBePlayed = false;
        mIsVideoSizeKnown = false;
    }
    public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {
        Log.v(TAG, "onVideoSizeChanged called");
        if (width == 0 || height == 0) {
            Log.e(TAG, "invalid video width(" + width + ") or height(" + height
                    + ")");
            return;
        }
        mIsVideoSizeKnown = true;
        mVideoWidth = width;
        mVideoHeight = height;
        if (mIsVideoReadyToBePlayed && mIsVideoSizeKnown) {
            startVideoPlayback();
        }
    }
    public void onPrepared(MediaPlayer mediaplayer) {
        Log.d(TAG, "onPrepared called");
        mIsVideoReadyToBePlayed = true;
        if (mIsVideoReadyToBePlayed && mIsVideoSizeKnown) {
            startVideoPlayback();
        }
    }

    @Override
    public void onCompletion(MediaPlayer mp) {
        // TODO Auto-generated method stub
    }
    @Override
    public void onBufferingUpdate(MediaPlayer mp, int percent) {
        // TODO Auto-generated method stub
    }
    private void startVideoPlayback() {
        Log.v(TAG, "startVideoPlayback");
        // holder.setFixedSize(mVideoWidth, mVideoHeight);
        mMediaPlayer.start();
    }
    @Override
    public void onDrawFrame(GL10 gl) {
        // TODO Auto-generated method stub
    }
    @Override
    public void onSurfaceChanged(GL10 gl, int width, int height) {
        // TODO Auto-generated method stub
    }
    @Override
    public void onSurfaceCreated(GL10 gl, EGLConfig config) {
        // TODO Auto-generated method stub
        Log.d(TAG, "GLPreview : onSurfaceCreated");
        playVideo();
    }
}

call custom GLsurfaceview :

GLPreview productView = new GLPreview(CloudReco.this, null); 

i don't know where i am missing. Thanks in advance.

Pratik
  • 30,639
  • 18
  • 84
  • 159
Ketan
  • 387
  • 2
  • 7
  • check out this links may be getting any idea http://stackoverflow.com/q/11431676/760489, http://sudarnimalan.blogspot.in/2012/06/android-play-video-on-top-of.html, http://www.makeuseof.com/tag/create-custom-video-player-website-vp-factory/ – Pratik Apr 06 '13 at 08:50

1 Answers1

0

In this case you should not implement SurfaceHolder.Callback from GLPreview because GLSurfaceView already sets the callback to the surfaceholder and calls renderer.surfacecreated . So you should only implement GLSurfaceView.Renderer methods - ondrawframe, onsurfacecreated(GL10 gl, EGLConfig config) . Refer to the GLsurfaceView source code. GLSurfaceView already implements surfaceCreated(SurfaceHolder holder); and calls your renderer

Satish
  • 320
  • 2
  • 9