title: SurfaceView does not display video from media player
body: <p>I am making a custom video player for which i am using surfaceview along with video player, but when I run the application, it just displays black screen and plays audio. </p>
  
  <p>My Code: </p>
  
  <pre><code>public class MainActivity extends Activity implements SurfaceHolder.Callback {
  
      private SeekBar seekbar;
      private ImageView ivPlay;
      private SurfaceView surfaceView;
      private SurfaceHolder surfaceHolder;
      private MediaPlayer mediaPlayer;
      private Handler mHandler;
      private Utilities utils;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          initObjects();
          playVideo();
      }
  
      private void initObjects() {
          seekbar = (SeekBar) findViewById(R.id.sbVideo);
          seekbar.setOnSeekBarChangeListener(seekbarChangeListener);
          mHandler = new Handler();
          utils = new Utilities();
          ivPlay = (ImageView) findViewById(R.id.ivPlay);
          ivPlay.setOnClickListener(new OnClickListener() {
  
              @Override
              public void onClick(View view) {
                  if (mediaPlayer.isPlaying()) {
                      if (mediaPlayer != null) {
                          mediaPlayer.pause();
                          // Changing button image to play button
                          ivPlay.setImageResource(R.drawable.ic_media_play);
                      }
                  } else {
                      // Resume song
                      if (mediaPlayer != null) {
                          mediaPlayer.start();
                          // Changing button image to pause button
                          ivPlay.setImageResource(R.drawable.ic_media_pause);
                      }
                  }
  
              }
          });
          surfaceView = (SurfaceView) findViewById(R.id.svVideoSurface);
          surfaceHolder = surfaceView.getHolder();
          surfaceHolder.addCallback(this);
          surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
  
          mediaPlayer = new MediaPlayer();
          mediaPlayer.setDisplay(surfaceHolder);
      }
  
      public void playVideo() {
          // Play song
  
          Uri uri = Uri
                  .parse("android.resource://com.videoplayer.demo/raw/title_video1");
  
          try {
  
              mediaPlayer.reset();
              mediaPlayer.setDataSource(MainActivity.this, uri);
  
              mediaPlayer.prepare();
              mediaPlayer.start();
  
              // Changing Button Image to pause image
              ivPlay.setImageResource(R.drawable.ic_media_pause);
  
              // set Progress bar values
              seekbar.setProgress(0);
              seekbar.setMax(100);
  
              // Updating progress bar
              updateProgressBar();
          } catch (IllegalArgumentException e) {
              e.printStackTrace();
          } catch (IllegalStateException e) {
              e.printStackTrace();
          } catch (IOException e) {
              e.printStackTrace();
          }
      }
  
      private OnSeekBarChangeListener seekbarChangeListener = new OnSeekBarChangeListener() {
  
          @Override
          public void onStopTrackingTouch(SeekBar seekbar) {
              mHandler.removeCallbacks(mUpdateTimeTask);
              int totalDuration = mediaPlayer.getDuration();
              int currentPosition = utils.progressToTimer(seekbar.getProgress(),
                      totalDuration);
  
              // forward or backward to certain seconds
              mediaPlayer.seekTo(currentPosition);
  
              // update timer progress again
              updateProgressBar();
  
          }
  
          @Override
          public void onStartTrackingTouch(SeekBar seekbar) {
              // TODO Auto-generated method stub
              mHandler.removeCallbacks(mUpdateTimeTask);
          }
  
          @Override
          public void onProgressChanged(SeekBar seekbar, int progress,
                  boolean fromUser) {
              // TODO Auto-generated method stub
  
          }
      };
  
      @Override
      public void surfaceChanged(SurfaceHolder holder, int arg1, int arg2, int arg3) {
          mediaPlayer.setDisplay(holder);
  
      }
  
      @Override
      public void surfaceCreated(SurfaceHolder holder) {
  
      }
  
      @Override
      public void surfaceDestroyed(SurfaceHolder arg0) {
          // TODO Auto-generated method stub
  
      }
  
      public void updateProgressBar() {
          mHandler.postDelayed(mUpdateTimeTask, 100);
      }
  
      private Runnable mUpdateTimeTask = new Runnable() {
          public void run() {
              long totalDuration = mediaPlayer.getDuration();
              long currentDuration = mediaPlayer.getCurrentPosition();
  
              // Updating progress bar
              int progress = (int) (utils.getProgressPercentage(currentDuration,
                      totalDuration));
              // Log.d("Progress", ""+progress);
              seekbar.setProgress(progress);
  
              // Running this thread after 100 milliseconds
              mHandler.postDelayed(this, 100);
          }
      };
  
      @Override
      protected void onDestroy() {
          super.onDestroy();
          mediaPlayer.release();
      };
  }
  </code></pre>
  
  <p>I don't know what I am doing wrong, any help would be great.</p>