0

I updated my app android API-23 to API-28 now MediaPlayer getDuration() method return -1, in api-23 getDuration method working fine but in latest api having issue. when using low quality (i.e 16kbs) of audio. but same time when i use high quality (64kbs to 192kbs) working fine.

MediaPlayer mp;
// 128kbs working fine in my app 
mp.setDataSource(http://www.villopim.com.br/android/Music_02.mp3);
// return actual time    
mp.getDuration();

// 16kbs working fine in my app 
mp.setDataSource(http://topappstopgames.com/appsdata/islamic/sn002.mp3);
// return -1    
mp.getDuration();

So how to resolve this issue in latest api.

Attaullah
  • 3,856
  • 3
  • 48
  • 63

2 Answers2

1

from the documentation

the duration in milliseconds, if no duration is available (for example, if streaming live content), -1 is returned.

but shouldn't you use this

mp.getDuration();

instead of this :

mediaPlayer.getDuration();

?

ismail alaoui
  • 5,748
  • 2
  • 21
  • 38
0

I shift to ExoPlayer now its working.

Attaullah
  • 3,856
  • 3
  • 48
  • 63