Search code examples
androidandroid-mediaplayerandroid-api-levels

Why MediaPlayer getDuration() method return -1 on low quality audio?


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.


Solution

  • I shift to ExoPlayer now its working.