I wanted to create a seekBar that tracks the progress of the media player, but it does not work well enough, the music plays, but the search remains inactive. Is there something I forgot?
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); seekBar = (SeekBar) findViewById(R.id.seekBar1); seekBar.setOnSeekBarChangeListener(this); } public void onClick(View v){ if(v == stopButton){ mediaPlayer.pause(); }else if(v == startButton){ mediaPlayer.start(); run(); }else if(v == quitButton ){ mediaPlayer.stop(); mediaPlayer.release(); } } public void run() { int currentPosition= 0; int total = mediaPlayer.getDuration(); while (mediaPlayer.isPlaying()) { currentPosition= mediaPlayer.getCurrentPosition(); seekBar.setProgress(currentPosition); } }
source share