示例#1
0
  public void onEvent(MusicPlayEvent event) {
    int duration = MusicService.durationOfSong();
    if (duration != 0) {
      seekbar.setMax(duration);
    } else {
      Toast.makeText(this, "cant update seekbar", Toast.LENGTH_SHORT).show();
    }

    seekbar.setOnSeekBarChangeListener(
        new SeekBar.OnSeekBarChangeListener() {

          @Override
          public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            if (fromUser) {
              if (MusicService.mediaPlayer != null) {
                MusicService.mediaPlayer.seekTo(progress);
              }
            }
          }

          @Override
          public void onStartTrackingTouch(SeekBar seekBar) {}

          @Override
          public void onStopTrackingTouch(SeekBar seekBar) {}
        });

    handler.sendEmptyMessage(MESSAGE_WAKE_UP_AND_SEEK);
    playMusic.setVisibility(View.GONE);
    pauseMusic.setVisibility(View.VISIBLE);
  }
示例#2
0
 @Override
 public void handleMessage(Message msg) {
   if (msg.what == MESSAGE_WAKE_UP_AND_SEEK) {
     int currentPos = MusicService.currentPosition();
     seekbar.setProgress(currentPos);
     sendEmptyMessageDelayed(MESSAGE_WAKE_UP_AND_SEEK, 200);
   }
   super.handleMessage(msg);
 }
示例#3
0
  public void onEvent(MusicActionEvent event) {

    seekbar.setProgress(MusicService.currentPosition());
  }