コード例 #1
0
 private void doPauseResume() {
   if (mFensterPlayer.isPlaying()) {
     mFensterPlayer.pause();
   } else {
     mFensterPlayer.start();
   }
   updatePausePlay();
 }
コード例 #2
0
  @Override
  public boolean dispatchKeyEvent(final KeyEvent event) {
    int keyCode = event.getKeyCode();
    final boolean uniqueDown =
        event.getRepeatCount() == 0 && event.getAction() == KeyEvent.ACTION_DOWN;
    if (keyCode == KeyEvent.KEYCODE_HEADSETHOOK
        || keyCode == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE
        || keyCode == KeyEvent.KEYCODE_SPACE) {
      if (uniqueDown) {
        doPauseResume();
        show(DEFAULT_TIMEOUT);
        if (mPauseButton != null) {
          mPauseButton.requestFocus();
        }
      }
      return true;
    } else if (keyCode == KeyEvent.KEYCODE_MEDIA_PLAY) {
      if (uniqueDown && !mFensterPlayer.isPlaying()) {
        mFensterPlayer.start();
        updatePausePlay();
        show(DEFAULT_TIMEOUT);
      }
      return true;
    } else if (keyCode == KeyEvent.KEYCODE_MEDIA_STOP || keyCode == KeyEvent.KEYCODE_MEDIA_PAUSE) {
      if (uniqueDown && mFensterPlayer.isPlaying()) {
        mFensterPlayer.pause();
        updatePausePlay();
        show(DEFAULT_TIMEOUT);
      }
      return true;
    } else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
        || keyCode == KeyEvent.KEYCODE_VOLUME_UP
        || keyCode == KeyEvent.KEYCODE_VOLUME_MUTE
        || keyCode == KeyEvent.KEYCODE_CAMERA) {
      // don't show the controls for volume adjustment
      return super.dispatchKeyEvent(event);
    } else if (keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_MENU) {
      if (uniqueDown) {
        hide();
      }
      return true;
    }

    show(DEFAULT_TIMEOUT);
    return super.dispatchKeyEvent(event);
  }
コード例 #3
0
  private void updatePausePlay() {
    if (mPauseButton == null) {
      return;
    }

    if (mFensterPlayer.isPlaying()) {
      mPauseButton.setImageResource(android.R.drawable.ic_media_pause);
    } else {
      mPauseButton.setImageResource(android.R.drawable.ic_media_play);
    }
  }
コード例 #4
0
 @Override
 public void handleMessage(final Message msg) {
   int pos;
   switch (msg.what) {
     case FADE_OUT:
       if (mFensterPlayer.isPlaying()) {
         hide();
       } else {
         // re-schedule to check again
         Message fadeMessage = obtainMessage(FADE_OUT);
         removeMessages(FADE_OUT);
         sendMessageDelayed(fadeMessage, DEFAULT_TIMEOUT);
       }
       break;
     case SHOW_PROGRESS:
       pos = setProgress();
       if (!mDragging && mShowing && mFensterPlayer.isPlaying()) {
         final Message message = obtainMessage(SHOW_PROGRESS);
         sendMessageDelayed(message, 1000 - (pos % 1000));
       }
       break;
   }
 }