Search code examples
androidaudioseekbar

Fire events at specific at specific progress as the seek bar progresses Android


I followed this tutorial to create an audio player.

Now I want to add some events that fires events when the player reaches a specific progress. For example, at 00:32 of the current audio, display a Toast.

The interface should look like this :

enter image description here

The white dots represents the events in this case. Any idea?


Solution

  • I found it guys, here is my code (that worked perfectly)

    private ImageView CreateWhiteDot(int time) {
        ImageView WhiteDot = new ImageView(getApplicationContext());
        float x = 0;
        float y = 0;
        WhiteDot.setImageResource(R.drawable.stop_dot_inactive);
        x = sbStopPlayerSlider.getX() + 15;
        x += ((sbStopPlayerSlider.getWidth() - 30) * time * 1000)
                / mpAudioPlayer.getDuration();
        WhiteDot.setX(x);
        y = sbStopPlayerSlider.getTranslationY()
                + sbStopPlayerSlider.getHeight() / 2;
        WhiteDot.setY(y);
        return WhiteDot;
    }