title: Playing video in a GLSurfaceView instead of SurfaceView
body: <p>I've been struggling with this for 2 days now...
  Following this answer: <a href="https://stackoverflow.com/a/2006454/444324">https://stackoverflow.com/a/2006454/444324</a> - it is mentioned that it's possible to play a video in a GLSurfaceView by altering the MediaPlayerDemo_Video example in API Demos:</p>
  
  <blockquote>
    <p>All you have to do there is to replace the SurfaceView with a
    GLSurfaceView in both the MediaPlayerDemo_Video.java file as well as
    in the corresponding layout file (mediaplayer_2.xml).</p>
    
    <p>Also you need to create a custom Renderer class (one that implements
    the GLSurfaceView.Renderer interface) and set it to your
    GLSurfaceView.</p>
  </blockquote>
  
  <p>I tried replacing the SurfaceView to a GLSurfaceView as suggested, also <a href="https://stackoverflow.com/q/2108600/444324">using this</a> but it just crashes on start:</p>
  
  <pre><code>07-11 14:54:22.086: E/AndroidRuntime(12373): FATAL EXCEPTION: main
  07-11 14:54:22.086: E/AndroidRuntime(12373): java.lang.NullPointerException
  07-11 14:54:22.086: E/AndroidRuntime(12373):    at android.opengl.GLSurfaceView.surfaceCreated(GLSurfaceView.java:512)
  07-11 14:54:22.086: E/AndroidRuntime(12373):    at android.view.SurfaceView.updateWindow(SurfaceView.java:533)
  07-11 14:54:22.086: E/AndroidRuntime(12373):    at android.view.SurfaceView.access$000(SurfaceView.java:81)
  07-11 14:54:22.086: E/AndroidRuntime(12373):    at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:169)
  07-11 14:54:22.086: E/AndroidRuntime(12373):    at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:590)
  07-11 14:54:22.086: E/AndroidRuntime(12373):    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1617)
  07-11 14:54:22.086: E/AndroidRuntime(12373):    at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2442)
  07-11 14:54:22.086: E/AndroidRuntime(12373):    at android.os.Handler.dispatchMessage(Handler.java:99)
  07-11 14:54:22.086: E/AndroidRuntime(12373):    at android.os.Looper.loop(Looper.java:137)
  07-11 14:54:22.086: E/AndroidRuntime(12373):    at android.app.ActivityThread.main(ActivityThread.java:4575)
  07-11 14:54:22.086: E/AndroidRuntime(12373):    at java.lang.reflect.Method.invokeNative(Native Method)
  07-11 14:54:22.086: E/AndroidRuntime(12373):    at java.lang.reflect.Method.invoke(Method.java:511)
  07-11 14:54:22.086: E/AndroidRuntime(12373):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
  07-11 14:54:22.086: E/AndroidRuntime(12373):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
  07-11 14:54:22.086: E/AndroidRuntime(12373):    at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>I know I can use a VideoView to play a video or just stay with SurfaceView with MediaPlayer but I must use a GLSurfaceView because I need this video to be played on top of the camera surface view.</p>
  
  <p>Thank you!</p>
  
  <p>Relevant code:
  my XML:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical" &gt;
  
      &lt;com.commonsware.android.camera.MyGLSurfaceView
          android:id="@+id/surface"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_gravity="center" /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>My Class:</p>
  
  <pre><code>public class MediaPlayerDemo_Video extends Activity implements
          OnBufferingUpdateListener, OnCompletionListener,
          OnPreparedListener, OnVideoSizeChangedListener, SurfaceHolder.Callback {
  
      private MediaPlayer mMediaPlayer;
      private MyGLSurfaceView mPreview;
      private SurfaceHolder holder;
  
      /**
       * 
       * Called when the activity is first created.
       */
      @Override
      public void onCreate(Bundle icicle) {
          super.onCreate(icicle);
          setContentView(R.layout.mediaplayer_2);
          mPreview = (MyGLSurfaceView) findViewById(R.id.surface);
          holder = mPreview.getHolder();
          holder.addCallback(this);
          holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
  
      }
  }
  </code></pre>
  
  <p>MyGLSurfaceView Class:</p>
  
  <pre><code>class MyGLSurfaceView extends android.opengl.GLSurfaceView {
      public MyGLSurfaceView(Context context, AttributeSet attrs) {
          super(context, attrs);
      }
  }
  </code></pre>