Android: Media Player Duration

I have installed:

mSeekBar.setMax(mp.getDuration()); // 8480 

After completing Audiofile, I get:

  player.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { public void onCompletion(MediaPlayer mediaPlayer) { Log.e("onComplete>>", ""+mediaPlayer.getCurrentPosition()); // mediaPlayer.getCurrentPosition() = 8192 Log.e("getDuration", ""+mediaPlayer.getDuration()); // mediaPlayer.getDuration() = 8480 if(mediaPlayer.getCurrentPosition()>=mediaPlayer.getDuration()) { // Why never get called??? } } }); 

So, why does the current position of MediaPlayer not reach the total duration of the audio file?

Or technically we can say:

Why not?

 mediaPlayer.getCurrentPosition()==mediaPlayer.getDuration() 

Why always

mediaPlayer.getCurrentPosition () <mediaPlayer.getDuration () in an OnCompletion listener?

Example:

I have a Play symbol to start the player. Now, when I click the play symbol, it is converted to the Pause symbol.

I have a maxduration file audiodfile.

Now I want to convert the Pause symbol to Play Symbol when the audio file is fully played. So what I am doing is checking:

 if(mediaPlayer.getCurrentPosition()>=mediaPlayer.getDuration()) { // Convert Imagview from Pause to Play // But never get called } 
+7
android media-player android-mediaplayer android-seekbar
source share
1 answer

If you need to complete some task upon completion by checking currentPoision for duration, you can do the trick below:

 if(mediaPlayer.getDuration()-mediaPlayer.getCurrentPosition()<1000){//milliseconds new Handler().postDelayed( new Runnable() { @Override public void run() { // Convert Imageview from Pause to Play } },1000); } 
0
source share

All Articles