MediaPlayer.getDuration()返回错误的时间 [英] MediaPlayer.getDuration() returning wrong duration

查看:10087
本文介绍了MediaPlayer.getDuration()返回错误的时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在MediaPlayer的 getDuration()方法是给我一段音频文件不正确的值。我认为所有这些文件的共同特点是,他们使用的Audacity或一些其他的音频编辑工具操纵。试图把MediaPlayer的进度的进度条时,这是一个问题。

The MediaPlayer's getDuration() method is giving me an incorrect value for some audio files. I think the common trait for all these files is that they were manipulated using Audacity or some other audio editing tool. This is a problem when trying to tie MediaPlayer progress to a Progress Bar.

我继续记录吧:

while(mPlayer.isPlaying())
    Log.i("progress/total", 
            mPlayer.getCurrentPosition() + 
            "/" + mPlayer.getDuration());

和发现这一点:

I/progress/total(643): 14615/14620
I/progress/total(643): 14647/14620

这是仅有的两个十万日志行,但问题是进度通过什么getDuration()认为是歌曲的总时长,它只是不断去后。因为MediaPlayer的其实可以给出时间正确的总,有没有用这个来得到适当的最大的为我的进度条的方式?

This is only two log line of thousands, but the point is after the progress passes what getDuration() believes to be the total duration of the song, it just keeps going. Because the MediaPlayer can in fact give the correct total for duration, is there a way to use this to get a proper maximum for my ProgressBar?

推荐答案

我已经当MediaPlayer.getDuration()返回542434毫秒MP3文件类似的问题(与ICS 4.0.3的HTC Desire C)。
文件本身约为89秒,差异太大。
我检查了MP3文件的内容,看到一些奇怪的XML,如:

I had similar problem when MediaPlayer.getDuration() returned 542434 ms for mp3 file (HTC Desire C with ICS 4.0.3). File itself was around 89 seconds, difference is too big. I checked mp3 file content and saw some strange xml like:

<?xpacket begin="п»ї" id="W5M0MpCehiHzreSzNTczkc9d"?>
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Adobe XMP Core 4.2.2-c063 53.351735, 2008/07/22-18:04:26        ">

保存此文件作为新之后,XML掉了getDuration()返回正确的值。
我知道,这将不利于那些谁需要打你不能修改文件,但对于那些谁可以 - 它应该帮助

After saving this file as new one that xml was dropped and getDuration() returned correct value. I know that it will not help those who need playing files you can't modify, but for those who can - it should help.

这篇关于MediaPlayer.getDuration()返回错误的时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆