Example #1
0
 private void toggleMediaControlsVisiblity() {
   if (mControls.isShowing()) {
     mControls.hide();
   } else {
     mControls.show();
   }
 }
Example #2
0
 private void removeControls() {
   if (mControls != null) {
     mControls.setEnabled(false);
     mControls.hide();
     mControls = null;
   }
 }
Example #3
0
 private void attachControls() {
   if (mControls != null) {
     mControls.setDelegate(this);
     mControls.setAnchorView(mVideoSurfaceView);
     mControls.setEnabled(false);
   }
 }
Example #4
0
 private void setControls(ContentVideoViewControls controls) {
   if (mControls != null) {
     mControls.hide();
   }
   mControls = controls;
   attachControls();
 }
Example #5
0
 @Override
 public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
   mVideoSurfaceView.setFocusable(true);
   mVideoSurfaceView.setFocusableInTouchMode(true);
   if (isInPlaybackState() && mControls != null) {
     mControls.show();
   }
 }
Example #6
0
 @Override
 public boolean onKey(View v, int keyCode, KeyEvent event) {
   boolean isKeyCodeSupported =
       keyCode != KeyEvent.KEYCODE_BACK
           && keyCode != KeyEvent.KEYCODE_VOLUME_UP
           && keyCode != KeyEvent.KEYCODE_VOLUME_DOWN
           && keyCode != KeyEvent.KEYCODE_VOLUME_MUTE
           && keyCode != KeyEvent.KEYCODE_CALL
           && keyCode != KeyEvent.KEYCODE_MENU
           && keyCode != KeyEvent.KEYCODE_SEARCH
           && keyCode != KeyEvent.KEYCODE_ENDCALL;
   if (isInPlaybackState() && isKeyCodeSupported && mControls != null) {
     if (keyCode == KeyEvent.KEYCODE_HEADSETHOOK || keyCode == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE) {
       if (isPlaying()) {
         pause();
         mControls.show();
       } else {
         start();
         mControls.hide();
       }
       return true;
     } else if (keyCode == KeyEvent.KEYCODE_MEDIA_PLAY) {
       if (!isPlaying()) {
         start();
         mControls.hide();
       }
       return true;
     } else if (keyCode == KeyEvent.KEYCODE_MEDIA_STOP
         || keyCode == KeyEvent.KEYCODE_MEDIA_PAUSE) {
       if (isPlaying()) {
         pause();
         mControls.show();
       }
       return true;
     } else {
       toggleMediaControlsVisiblity();
     }
   } else if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_UP) {
     exitFullscreen(false);
     return true;
   } else if (keyCode == KeyEvent.KEYCODE_MENU || keyCode == KeyEvent.KEYCODE_SEARCH) {
     return true;
   }
   return super.onKeyDown(keyCode, event);
 }
Example #7
0
  @CalledByNative
  private void onUpdateMediaMetadata(
      int videoWidth,
      int videoHeight,
      int duration,
      boolean canPause,
      boolean canSeekBack,
      boolean canSeekForward) {
    mProgressView.setVisibility(View.GONE);
    mDuration = duration;
    mCanPause = canPause;
    mCanSeekBack = canSeekBack;
    mCanSeekForward = canSeekForward;
    mCurrentState = isPlaying() ? STATE_PLAYING : STATE_PAUSED;
    if (mControls != null) {
      mControls.setEnabled(true);
      // If paused , should show the controller for ever.
      if (isPlaying()) mControls.show();
      else mControls.show(0);
    }

    onVideoSizeChanged(videoWidth, videoHeight);
  }
Example #8
0
  @CalledByNative
  public void onMediaPlayerError(int errorType) {
    Log.d(TAG, "OnMediaPlayerError: " + errorType);
    if (mCurrentState == STATE_ERROR || mCurrentState == STATE_PLAYBACK_COMPLETED) {
      return;
    }

    // Ignore some invalid error codes.
    if (errorType == MEDIA_ERROR_INVALID_CODE) {
      return;
    }

    mCurrentState = STATE_ERROR;
    if (mControls != null) {
      mControls.hide();
    }

    /* Pop up an error dialog so the user knows that
     * something bad has happened. Only try and pop up the dialog
     * if we're attached to a window. When we're going away and no
     * longer have a window, don't bother showing the user an error.
     *
     * TODO(qinmin): We need to review whether this Dialog is OK with
     * the rest of the browser UI elements.
     */
    if (getWindowToken() != null) {
      String message;

      if (errorType == MEDIA_ERROR_NOT_VALID_FOR_PROGRESSIVE_PLAYBACK) {
        message = mPlaybackErrorText;
      } else {
        message = mUnknownErrorText;
      }

      new AlertDialog.Builder(getContext())
          .setTitle(mErrorTitle)
          .setMessage(message)
          .setPositiveButton(
              mErrorButton,
              new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                  /* Inform that the video is over.
                   */
                  onCompletion();
                }
              })
          .setCancelable(false)
          .show();
    }
  }
Example #9
0
 private void onCompletion() {
   mCurrentState = STATE_PLAYBACK_COMPLETED;
   if (mControls != null) {
     mControls.hide();
   }
 }