Q: How to find out if audio is ready to play after changing position of streaming audio by seekbar? I using MediaPlayer to streaming a audio from a url. all thing is working. but when user changes seekbar to change position of playing audio, a short time take long to prepare audio to play.after user changes seek bar position, I showing a ProgressBar. what I want something like a listener to find out player is now playing and hide ProgressBar
my code is:
public class TestActivity extends AppCompatActivity {
  private ImageButton podcastBtn;
  private SeekBar     podcastSeek;
  private TextView    podcastFullTime;
  private TextView    podcastCurrentTime;
  private ProgressBar podcastPrg;

  private   MediaPlayer mediaPlayer;
  private boolean     podcastInitialized;
  private String myUrl = "http://www.archive.org/download/AmericanStories/The_Boarded_Window_-_By_Ambrose_Bierce.mp3";

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_media_detail);

    findViews();

    mediaPlayer = new MediaPlayer();
    mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
      @SuppressLint("DefaultLocale")
      @Override
      public void onPrepared(final MediaPlayer mp) {
        int audioLength = mp.getDuration();
        podcastSeek.setMax(audioLength);
        podcastFullTime.setText(String.format("%02d : %02d",
                TimeUnit.MILLISECONDS.toMinutes(audioLength),
                TimeUnit.MILLISECONDS.toSeconds(audioLength) -
                        TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(audioLength))
        ));

        new Thread(new Runnable() {
          @Override
          public void run() {
            while (mp.getCurrentPosition() < mp.getDuration()) {
              final int millis = mp.getCurrentPosition();

              runOnUiThread(new Runnable() {
                @Override
                public void run() {
                  podcastSeek.setProgress(mp.getCurrentPosition());
                  podcastCurrentTime.setText(String.format("%02d : %02d",
                          TimeUnit.MILLISECONDS.toMinutes(millis),
                          TimeUnit.MILLISECONDS.toSeconds(millis) -
                                  TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millis))
                  ));
                }
              });

              try {
                Thread.sleep(100);
              } catch (InterruptedException e) {
                e.printStackTrace();
              }
            }
          }
        }).start();

      }
    });

    podcastBtn.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
        if (!mediaPlayer.isPlaying()) {
          if (!podcastInitialized) {
            new AudioPlayerAsync().execute(myUrl);
          } else {
            mediaPlayer.start();
            podcastBtn.setImageResource(R.drawable.pause_icon);
          }

        } else {
          mediaPlayer.pause();
          podcastBtn.setImageResource(R.drawable.play_icon);

        }

      }

    });

    podcastSeek.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
      @Override
      public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
        if (fromUser && podcastInitialized) {
          mediaPlayer.seekTo(progress);
          podcastPrg.setVisibility(View.VISIBLE);
          podcastBtn.setVisibility(View.INVISIBLE);

        }
      }

      @Override
      public void onStartTrackingTouch(SeekBar seekBar) {}

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

  }

  class AudioPlayerAsync extends AsyncTask<String, Void, Void> {

    @Override
    protected void onPreExecute() {
      super.onPreExecute();

      podcastPrg.setVisibility(View.VISIBLE);
      podcastBtn.setVisibility(View.INVISIBLE);
    }

    @Override
    protected Void doInBackground(String... strings) {
      try {
        mediaPlayer.setDataSource(strings[0]);
        mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
          @Override
          public void onCompletion(MediaPlayer mediaPlayer) {
            podcastInitialized = false;
            mediaPlayer.stop();
            mediaPlayer.reset();
          }
        });

        mediaPlayer.prepare();

      } catch (Exception e) {
        Log.e("tag", e.getMessage());
      }
      return null;

    }

    @Override
    protected void onPostExecute(Void aVoid) {
      super.onPostExecute(aVoid);

      podcastPrg.setVisibility(View.GONE);
      podcastBtn.setVisibility(View.VISIBLE);
      podcastBtn.setImageResource(R.drawable.pause_icon);

      mediaPlayer.start();
      podcastInitialized = true;
    }
  }

  @Override
  protected void onPause() {
    super.onPause();
    mediaPlayer.pause();
  }

  @Override
  protected void onResume() {
    super.onResume();
    if (podcastInitialized) {
      mediaPlayer.start();
    }
  }

  @Override
  public void onBackPressed() {
    mediaPlayer.stop();
    finish();
    super.onBackPressed();

  }

}


A: I found sulotion:
 mediaPlayer.setOnBufferingUpdateListener(new MediaPlayer.OnBufferingUpdateListener() {
        @Override
        public void onBufferingUpdate(MediaPlayer mp, int percent) {

            float currentPlayingPercent = (100 * mp.getCurrentPosition() / (float)mp.getDuration());
            Log.i("tag", "buffer percent: " + percent);
            Log.i("tag", "media player percent: " + currentPlayingPercent);

            if (podcastPrg.getVisibility() == View.VISIBLE && percent > currentPlayingPercent) {
                podcastPrg.setVisibility(View.GONE);
                podcastBtn.setVisibility(View.VISIBLE);
            }
        }
    });

