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); }
@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); }
public void onEvent(MusicActionEvent event) { seekbar.setProgress(MusicService.currentPosition()); }