MediaPlayer getDuration返回-1412558917 [英] MediaPlayer getDuration returns -1412558917
本文介绍了MediaPlayer getDuration返回-1412558917的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我完全迷失了.我发现代码非常简单,并且在文档中没有找到为什么会返回那么大的负数的任何原因.代码如下
I'm totally lost in this. I found the code pretty simple, and didn't find in the documentation any reason why would return a negative number that large. The code is as follows
private int getDuration(String audioPath) throws Exception {
mediaPlayer = new MediaPlayer(); // This variable was created globally
mediaPlayer.setDataSource(audioPath);
return mediaPlayer.getDuration(); // Here it returns -1412558917 in every audio file i record, no matter if it's 3 seconds long or 8
}
我认为记录方式并不重要,但是如果我记错了,我将添加代码.我保存文件的格式是3gp.在此之后,我可以重现音频,所以我不知道可能是什么问题
I think that it doesn't matter how I record it, but if I'm mistaken I'll add the code. The format I save the file is 3gp. I'm able to reproduce the audio after this, so I don't know what might be the problem
谢谢
推荐答案
在返回持续时间之前,您是否尝试过添加 mediaPlayer.prepare();
?
Have you tried adding mediaPlayer.prepare();
before you return the duration?
这篇关于MediaPlayer getDuration返回-1412558917的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文