private int setProgress() {
    if (mFensterPlayer == null || mDragging) {
      return 0;
    }
    int position = mFensterPlayer.getCurrentPosition();
    int duration = mFensterPlayer.getDuration();
    if (mProgress != null) {
      if (duration > 0) {
        // use long to avoid overflow
        long pos = 1000L * position / duration;
        mProgress.setProgress((int) pos);
      }
      int percent = mFensterPlayer.getBufferPercentage();
      mProgress.setSecondaryProgress(percent * 10);
    }

    if (mEndTime != null) {
      mEndTime.setText(stringForTime(duration));
    }
    if (mCurrentTime != null) {
      mCurrentTime.setText(stringForTime(position));
    }
    final int playedSeconds = position / 1000;
    if (lastPlayedSeconds != playedSeconds) {
      lastPlayedSeconds = playedSeconds;
    }
    return position;
  }
 private void doPauseResume() {
   if (mFensterPlayer.isPlaying()) {
     mFensterPlayer.pause();
   } else {
     mFensterPlayer.start();
   }
   updatePausePlay();
 }
        public void onProgressChanged(
            final SeekBar bar, final int progress, final boolean fromuser) {
          if (!fromuser && !mManualDragging) {
            // We're not interested in programmatically generated changes to
            // the progress bar's position.
            return;
          }

          long duration = mFensterPlayer.getDuration();
          long newposition = (duration * progress) / 1000L;
          mFensterPlayer.seekTo((int) newposition);
          if (mCurrentTime != null) {
            mCurrentTime.setText(stringForTime((int) newposition));
          }
        }
  @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);
  }
  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);
    }
  }
 @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;
   }
 }