I'm developing an audio player, creating a Notification in Mediastyle style, with play, pause and seekbar buttons. The seekbar is updated once every half a second, taking the value from the current position of the media player. And everything works fine until the user independently starts rewinding the seekbar.
When the user moves the slider, a callback is triggered:
MediaSession.setCallback(new MediaSessionCompat.Callback() {
@Override
public void onSeekTo(long pos) {
mediaPlayer.seekTo((int)position);
}
But due to the fact that the seekbar is updated every half a second, the user cannot move the seekbar slider indefinitely. Question: How can I stop updating the seekbar reading while it is being manipulated by the user. I know that seekbar has callbacks:
private boolean isTouch;
public void setSeekbar(SeekBar seekBarPlayer) {
seekBarPlayer.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
isTouch = true;
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
isTouch = false;
}
});
}
But I can't intercept them since I don't have a reference to the current seekbar to override the callbacks.