[英]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. 我将我的应用程序Android API-23更新为API-28,现在
MediaPlayer getDuration()
方法return -1 ,在api-23 getDuration方法中工作正常,但最新的api有问题。 when using low quality (ie 16kbs) of audio. 使用低质量(即16kbs)的音频时。 but same time when i use high quality (64kbs to 192kbs) working fine.
但同时,当我使用高质量(64kbs至192kbs)时,工作正常。
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. 因此,如何在最新的api中解决此问题。
from the documentation 从文档中
the duration in milliseconds, if no duration is available (for example, if streaming live content), -1 is returned.
持续时间(以毫秒为单位),如果没有可用的持续时间(例如,流实时内容),则返回-1。
but shouldn't you use this 但是你不应该使用这个
mp.getDuration();
instead of this : 代替这个:
mediaPlayer.getDuration();
? ?
我现在转到ExoPlayer了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.