Cannot resume from video play

I implemented the video player following http://www.cocos2d-x.org/forums/6/topics/28302?r=30266

It works, but when it returns to game after video, I got:

12-30 12:35:24.346: W/MediaPlayer(31047): info/warning (3, 0)
12-30 12:37:04.583: D/Cocos2dxActivity(31047): resume
12-30 12:37:04.613: D/cocos2d-x debug info(31047): OpenGL error 0x0502 in jni/…/…/…/cocos2dx/sprite_nodes/CCSprite.cpp draw 584

It seems videoview has messed up opengl surface. I’ve tried to call ccGLInvalidateStateCache()+setGLDefaultValues() but got no effect

Environment: nexus4, android 4.4 sdk, ndk r8e, cocos2d-x v2.2.1

Attached is the code.

Version 1( Almost the same with Pawel Lopusinski, thanks) using a seperate Activity

public class Cocos2dxVideo extends Activity implements MediaPlayer.OnPreparedListener, MediaPlayer.OnCompletionListener{
    static private Activity me = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        me = this;
        // FrameLayout
        ViewGroup.LayoutParams framelayout_params =
            new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                                       ViewGroup.LayoutParams.MATCH_PARENT);
        FrameLayout framelayout = new FrameLayout(this);
        framelayout.setLayoutParams(framelayout_params);

        String filename = getIntent().getStringExtra("FILENAME");
        int i = filename.lastIndexOf('.');
        filename = filename.substring(0, i);
        filename = filename.toLowerCase(Locale.US);

        Resources res = getResources();
        int id = res.getIdentifier(filename, "raw", getPackageName());
        if(id == 0){
            Log.e("video", filename+" not found");
            moviePlaybackFinished();
            return;
        }

        VideoView m_videoView = new VideoView(this);
        framelayout.addView(m_videoView);
        FrameLayout.LayoutParams linearParams = (FrameLayout.LayoutParams) m_videoView.getLayoutParams();
        linearParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
        linearParams.height = FrameLayout.LayoutParams.WRAP_CONTENT;
        linearParams.gravity = Gravity.CENTER;
        m_videoView.setLayoutParams(linearParams);

        MediaController mc = new MediaController(this);
        mc.setAnchorView(m_videoView);
        mc.setMediaPlayer(m_videoView);

        m_videoView.setMediaController(mc);
        m_videoView.setVideoURI(Uri.parse("android.resource://" + 
                getPackageName() + "/" + id));

        m_videoView.setOnPreparedListener(this);
        m_videoView.setOnCompletionListener(this);

        m_videoView.requestFocus();
        m_videoView.start();

        setContentView(framelayout);
    }

    public static void remove() {
        me.finish();
    }

    public void onPrepared(MediaPlayer mp) {
        mp.setLooping(false);
        //movieStartsPlaying();
    }

    public void onCompletion(MediaPlayer mp) {
        Cocos2dxVideo.remove();
    };

    public static native void moviePlaybackFinished();

Version 2

public class Cocos2dxVideo2 implements MediaPlayer.OnPreparedListener, MediaPlayer.OnCompletionListener{
    private static VideoView m_videoView = null;

    public static void display(String filename) {
        Cocos2dxActivity activity = Cocos2dxActivity.getContext();

        int i = filename.lastIndexOf('.');
        filename = filename.substring(0, i);
        filename = filename.toLowerCase(Locale.US);

        Resources res = activity.getResources();
        int id = res.getIdentifier(filename, "raw", activity.getPackageName());
        if(id == 0){
            Log.e("VideoView", "unable to find "+filename);
            Cocos2dxVideo.moviePlaybackFinished();
            return;
        }
        Log.d("VideoView", "playing " + filename);

        m_videoView = new VideoView(activity);
        activity.getFrameLayout().addView(m_videoView);
        FrameLayout.LayoutParams linearParams = (FrameLayout.LayoutParams) m_videoView.getLayoutParams();
        linearParams.width = 400;//FrameLayout.LayoutParams.MATCH_PARENT;
        linearParams.height = 400;//FrameLayout.LayoutParams.WRAP_CONTENT;
        linearParams.gravity = Gravity.CENTER;
        m_videoView.setLayoutParams(linearParams);

        m_videoView.setZOrderOnTop(true);

        MediaController mc = new MediaController(activity);
        mc.setAnchorView(m_videoView);
        mc.setMediaPlayer(m_videoView);

        m_videoView.setMediaController(mc);
        m_videoView.setVideoURI(Uri.parse("android.resource://" + 
                activity.getPackageName() + "/" + id));

        Cocos2dxVideo2 callback = new Cocos2dxVideo2();
        m_videoView.setOnPreparedListener(callback);
        m_videoView.setOnCompletionListener(callback);

        m_videoView.requestFocus();
        m_videoView.start();
    }

    @Override
    public void onPrepared(MediaPlayer mp) {
        mp.setLooping(false);
    };

    @Override
    public void onCompletion(MediaPlayer mp) {
        Cocos2dxActivity.getContext().getFrameLayout().removeView(m_videoView);
        Cocos2dxVideo.moviePlaybackFinished();
    }

After playing video, I finish the activity(version 1) or remove the webview, and got:

12-31 09:38:44.196: W/Adreno-ES20(10253): <__load_uniform_float:849>: GL_INVALID_OPERATION
12-31 09:38:44.196: D/cocos2d-x debug info(10253): OpenGL error 0x0502 in jni/../../../cocos2dx/sprite_nodes/CCSprite.cpp draw 584
12-31 09:38:44.196: W/Adreno-ES20(10253): <__load_uniform_float:849>: GL_INVALID_OPERATION
12-31 09:38:44.196: D/cocos2d-x debug info(10253): OpenGL error 0x0502 in jni/../../../cocos2dx/sprite_nodes/CCSprite.cpp draw 584

Wooooooops, worked out after struggling three days

The problem lies in GL threads. It seems I accidentally call draw in non GL thread, which makes the GL states completely wrong:(

hi,how did you figure it?

I put the video call in the GL thread and everything works now