@Override // async task thread
 protected Void doInBackground(Void... params) {
   try {
     mPlayer.setLoopMode(mLoop);
     mPlayer.play(mCallback);
   } catch (IOException ioe) {
     Log.e(TAG, "movie playback failed", ioe);
   } finally {
     mSurface.release();
   }
   return null;
 }
  /** onClick handler for "play"/"stop" button. */
  public void clickPlayStop(@SuppressWarnings("unused") View unused) {
    if (mShowStopLabel) {
      Log.d(TAG, "stopping movie");
      stopPlayback();
      // Don't update the controls here -- let the task thread do it after the movie has
      // actually stopped.
      // mShowStopLabel = false;
      // updateControls();
    } else {
      if (mPlayTask != null) {
        Log.w(TAG, "movie already playing");
        return;
      }

      Log.d(TAG, "starting movie");
      SpeedControlCallback callback = new SpeedControlCallback();
      SurfaceHolder holder = mSurfaceView.getHolder();
      Surface surface = holder.getSurface();

      // Don't leave the last frame of the previous video hanging on the screen.
      // Looks weird if the aspect ratio changes.
      clearSurface(surface);

      MoviePlayer player = null;
      try {
        player =
            new MoviePlayer(
                new File(getFilesDir(), mMovieFiles[mSelectedMovie]), surface, callback);
      } catch (IOException ioe) {
        Log.e(TAG, "Unable to play movie", ioe);
        surface.release();
        return;
      }

      AspectFrameLayout layout = (AspectFrameLayout) findViewById(R.id.playMovie_afl);
      int width = player.getVideoWidth();
      int height = player.getVideoHeight();
      layout.setAspectRatio((double) width / height);
      // holder.setFixedSize(width, height);

      mPlayTask = new MoviePlayer.PlayTask(player, this);

      mShowStopLabel = true;
      updateControls();
      mPlayTask.execute();
    }
  }
  /** onClick handler for "play"/"stop" button. */
  public void clickPlayStop(@SuppressWarnings("unused") View unused) {
    if (mShowStopLabel) {
      Log.d(TAG, "stopping movie");
      stopPlayback();
      // Don't update the controls here -- let the async task do it after the movie has
      // actually stopped.
      // mShowStopLabel = false;
      // updateControls();
    } else {
      if (mPlayTask != null) {
        Log.w(TAG, "movie already playing");
        return;
      }
      Log.d(TAG, "starting movie");
      SpeedControlCallback callback = new SpeedControlCallback();
      if (((CheckBox) findViewById(R.id.locked60fps_checkbox)).isChecked()) {
        callback.setFixedPlaybackRate(60);
      }
      SurfaceTexture st = mTextureView.getSurfaceTexture();
      Surface surface = new Surface(st);
      MoviePlayer player = null;
      try {
        player = new MoviePlayer(new File(getFilesDir(), mMovieFiles[mSelectedMovie]), surface);
      } catch (IOException ioe) {
        Log.e(TAG, "Unable to play movie", ioe);
        surface.release();
        return;
      }
      adjustAspectRatio(player.getVideoWidth(), player.getVideoHeight());
      mPlayTask = new PlayMovieTask(player, surface, callback);
      if (((CheckBox) findViewById(R.id.loopPlayback_checkbox)).isChecked()) {
        mPlayTask.setLoopMode(true);
      }

      mShowStopLabel = true;
      updateControls();
      mPlayTask.execute();
    }
  }