Why is mediaPlayer.getCurrentPosition () less than getDuration () when it is complete?

    seekBar.setMax(mediaPlayer.getDuration());

When a media player is playing,

    //100 milliseconds
    seekBar.setProgress(mediaPlayer.getCurrentPosition());

But seekBar cannot search max,

    mediaPlayer.setOnCompletionListener(new OnCompletionListener() {

        @Override
        public void onCompletion(MediaPlayer mp) {
            LogUtil.d(TAG, "CurrentPosition = " + mp.getCurrentPosition(+ " -- Duration = " + mp.getDuration());
        }
    });

I found that mediaPlayer.getCurrentPosition () is always less than mediaPlayer.getDuration (). If I use seekBar.setProgress (mp.getDuration ()) when it is complete, the seekBar animation will not be smooth.

So why is getCurrentPosition () less than getDuration () when it is complete?

Sorry for my English.

+4
source share

Source: https://habr.com/ru/post/1598849/


All Articles