Exemple #1
0
 private void toggleMediaControlsVisiblity() {
   if (mMediaController.isShowing()) {
     mMediaController.hide();
   } else {
     mMediaController.show();
   }
 }
Exemple #2
0
  @Override
  public boolean onKeyDown(int keyCode, KeyEvent event) {
    boolean isKeyCodeSupported =
        keyCode != KeyEvent.KEYCODE_BACK
            && keyCode != KeyEvent.KEYCODE_VOLUME_UP
            && keyCode != KeyEvent.KEYCODE_VOLUME_DOWN
            && keyCode != KeyEvent.KEYCODE_MENU
            && keyCode != KeyEvent.KEYCODE_CALL
            && keyCode != KeyEvent.KEYCODE_ENDCALL;
    if (isInPlaybackState() && isKeyCodeSupported && mMediaController != null) {
      if (keyCode == KeyEvent.KEYCODE_HEADSETHOOK
          || keyCode == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE
          || keyCode == KeyEvent.KEYCODE_SPACE) {
        if (mMediaPlayer.isPlaying()) {
          pause();
          mMediaController.show();
        } else {
          start();
          mMediaController.hide();
        }
        return true;
      } else if (keyCode == KeyEvent.KEYCODE_MEDIA_STOP && mMediaPlayer.isPlaying()) {
        pause();
        mMediaController.show();
      } else {
        toggleMediaControlsVisiblity();
      }
    }

    return super.onKeyDown(keyCode, event);
  }
Exemple #3
0
  private void attachMediaController() {
    if (mMediaPlayer != null && mMediaController != null) {
      mMediaController.setMediaPlayer(this);
      View anchorView = this.getParent() instanceof View ? (View) this.getParent() : this;
      mMediaController.setAnchorView(anchorView);
      mMediaController.setEnabled(isInPlaybackState());

      if (mUri != null) {
        List<String> paths = mUri.getPathSegments();
        String name = paths == null || paths.isEmpty() ? "null" : paths.get(paths.size() - 1);
        mMediaController.setFileName(name);
      }
    }
  }
Exemple #4
0
        public boolean onError(MediaPlayer mp, int framework_err, int impl_err) {
          Log.d("Error: %d, %d", framework_err, impl_err);
          mCurrentState = STATE_ERROR;
          mTargetState = STATE_ERROR;
          if (mMediaController != null) mMediaController.hide();

          if (mOnErrorListener != null) {
            if (mOnErrorListener.onError(mMediaPlayer, framework_err, impl_err)) return true;
          }

          if (getWindowToken() != null) {
            int message =
                framework_err == MediaPlayer.MEDIA_ERROR_NOT_VALID_FOR_PROGRESSIVE_PLAYBACK
                    ? R.string.VideoView_error_text_invalid_progressive_playback
                    : R.string.VideoView_error_text_unknown;

            new AlertDialog.Builder(mContext)
                .setTitle(R.string.VideoView_error_title)
                .setMessage(message)
                .setPositiveButton(
                    R.string.VideoView_error_button,
                    new DialogInterface.OnClickListener() {
                      public void onClick(DialogInterface dialog, int whichButton) {
                        if (mOnCompletionListener != null)
                          mOnCompletionListener.onCompletion(mMediaPlayer);
                      }
                    })
                .setCancelable(false)
                .show();
          }
          return true;
        }
Exemple #5
0
 public void onCompletion(MediaPlayer mp) {
   Log.d("onCompletion");
   mCurrentState = STATE_PLAYBACK_COMPLETED;
   mTargetState = STATE_PLAYBACK_COMPLETED;
   if (mMediaController != null) mMediaController.hide();
   if (mOnCompletionListener != null) mOnCompletionListener.onCompletion(mMediaPlayer);
 }
Exemple #6
0
 public void setMediaController(MediaController controller) {
   if (mMediaController != null) mMediaController.hide();
   mMediaController = controller;
   attachMediaController();
 }