0
 mediaPlayer = new MediaPlayer();
 try {
        mediaPlayer.setDataSource(url);
        mediaPlayer.prepare();                    
     } catch (IOException e) {
       e.printStackTrace();
     }
     mediaPlayer.start();

this is my mediaplayer for play voice from url

Jatin
  • 1,650
  • 3
  • 17
  • 32
  • Take a look at the various callbacks: https://developer.android.com/reference/android/media/MediaPlayer#callbacks – msbit Aug 14 '21 at 10:23
  • Does this answer your question? [How to get buffering percent of VideoView on Android](https://stackoverflow.com/questions/12278873/how-to-get-buffering-percent-of-videoview-on-android) – Omar Shawky Aug 16 '21 at 15:21
  • @OmarShawky `MediaPlayer` is not `VideoView` – Ryan M Aug 16 '21 at 23:30
  • well in the question he did mention existence of a method to override named `onBufferingUpdate `, which you can read about here : https://developer.android.com/reference/android/media/MediaPlayer.OnBufferingUpdateListener – Omar Shawky Aug 17 '21 at 14:38

1 Answers1

0

You can have in a Thread or Coroutine Job the following code:

while(player.isRunning) {
  
  val percentage = (player.currentPosition / player.duration.toFloat())
  ...
}
Moro
  • 36
  • 4