@Override
 public void onConfigurationChanged(Configuration newConfig) {
   super.onConfigurationChanged(newConfig);
   if (mVideoWidth > 0 && mVideoHeight > 0)
     mVideoSurface.adjustSize(
         getDeviceWidth(this),
         getDeviceHeight(this),
         mVideoSurface.getWidth(),
         mVideoSurface.getHeight());
 }
 // Implement MediaPlayer.OnPreparedListener
 @Override
 public void onPrepared(MediaPlayer mp) {
   // setup video controller view
   controller.setMediaPlayerControlListener(this);
   mLoadingView.setVisibility(View.GONE);
   mVideoSurface.setVisibility(View.VISIBLE);
   controller.setAnchorView((FrameLayout) findViewById(R.id.videoSurfaceContainer));
   controller.setGestureListener(this);
   mMediaPlayer.start();
 }
 @Override
 public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {
   mVideoHeight = mp.getVideoHeight();
   mVideoWidth = mp.getVideoWidth();
   if (mVideoHeight > 0 && mVideoWidth > 0)
     mVideoSurface.adjustSize(
         mContentView.getWidth(),
         mContentView.getHeight(),
         mMediaPlayer.getVideoWidth(),
         mMediaPlayer.getVideoHeight());
 }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    Log.e(TAG, "onCreate");
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_video_player);

    mVideoSurface = (ResizeSurfaceView) findViewById(R.id.videoSurface);
    mContentView = findViewById(R.id.video_container);
    mLoadingView = findViewById(R.id.loading);
    SurfaceHolder videoHolder = mVideoSurface.getHolder();
    videoHolder.addCallback(this);

    mMediaPlayer = new MediaPlayer();
    mMediaPlayer.setOnVideoSizeChangedListener(this);
    controller = new VideoControllerView(this);
    mLoadingView.setVisibility(View.VISIBLE);

    try {
      mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
      mMediaPlayer.setDataSource(
          this, Uri.parse("http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4"));
      mMediaPlayer.setOnPreparedListener(this);
    } catch (IllegalArgumentException e) {
      e.printStackTrace();
    } catch (SecurityException e) {
      e.printStackTrace();
    } catch (IllegalStateException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }

    mVideoSurface.setOnTouchListener(
        new View.OnTouchListener() {
          @Override
          public boolean onTouch(View v, MotionEvent event) {
            controller.toggleContollerView();
            return false;
          }
        });
  }