MediaPlayer.seekTo精度(INT毫秒)精度、MediaPlayer、seekTo、INT

2023-09-13 00:08:18 作者:风吹过老故事

为什么 MediaPlayer.seekTo(INT毫秒)如此不准确?

它有时30秒早期(带MP3的变量和常量比特率)!与音频寻求本身有问题或这个方法打破?难道做缓冲还是什么?

It's sometimes 30 seconds early (with mp3's of both variable and constant bitrates)! Is seeking with audio inherently problematic or is this method broken? Is it to do with buffering or what?

我也注意到,总运行时间 getDuration()可能是错的(这是不是一个大问题),我已经测试了 getCurrentPosition()是不够准确(如在播放每n秒,它增加了n个千元)。我在Android 2.2。

I've also noticed that the total runtime getDuration() can be wrong (which isn't a big issue) and I've tested that getCurrentPosition() is accurate enough (as in every n seconds of playback, it increases by n thousand). I'm on Android 2.2.

最后,没有任何人知道哪些格式(如果有)实际上,它始终如一地为($ P $比WAV pferably其它其中presumably它)?

Finally, does anybody know which formats if any it actually works consistently for (preferably other than wav which presumably it does)?

编辑:

我主要是听播客。 smodcast和思维允许已经存在问题了几次,即使被转换/重恩coded到CBR。这些文件不会被损坏。

I mainly listen to podcasts. smodcast and Thinking Allowed have been problematic several times, even after being converted/re-encoded to CBR. The files aren't corrupted.

QuickMediaConverter(Windows)中似乎工作确定,但声音转换器(Ubuntu的)已经产生了一些不可靠的文件。我会尽力坚持原...

QuickMediaConverter (Windows) seems to work ok but Sound Converter (Ubuntu) has generated some dodgy files. I'll try sticking to the former...

更新:QuickMediaConverter作品真的很好,但不知道为什么。由于!没有问题

UPDATE: QuickMediaConverter works really well but no idea why. No problems since!

推荐答案

有其中一个多媒体框架将执行一个多媒体(AV)文件查找操作两种方式。

There are two ways in which a multimedia framework will perform a seek operation on a multimedia (AV) file.

力求关键帧 - 视频当EN codeD通常会有一些所谓的I帧或关键帧,这意味着这个框架有大量的信息,并可以用来去$ C其全部$ CA框架。为了减少空间的所有的帧都没有连接codeD作为关键帧的数量,而不是它们连接codeD为P(predicted)帧或predicted框架,这意味着你可以去$ C $与来自关键帧的帮助CA P帧。

Seek to Key frame - The video when encoded will usually have something called as the I frame or the Key frame, it means that this frame has lot of information and can be used to decode a frame in its entirety. To reduce the amount of space all the frames are not encoded as key frames instead they are encoded as P (Predicted) frames or predicted frames, meaning you can decode a P frame with the help from the key frame.

因此​​,搜索操作期间,在此情况下,寻求做是为最接近的关键帧为给定的持续时间。例如,如果用户试图40secs和最接近的关键帧是在第35秒,然后求做是为了在第35秒,而不是40秒

So during the seek operation, in this case the seeking is done to the closest key frame for a given time duration. For example if the user seeks to 40secs and the closest key frame is at 35th sec then seeking is done to the 35th sec and not to the 40th second.

寻求到时间 - 这是寻求在准确的时间,用户的需求。

Seek to Time - This is seeking to the accurate time that the user demands.

的追求仍然是完成在最近的关键帧,否则你会看到绿色的补丁或者是极不可取的视频的像素化。因此,不是寻道做是为了关键帧然后帧是德$ C $光盘直到所需的时间,但这些帧被丢弃,并且不向用户显示。在上面的例子中,所有的德$ C $光盘从第35到第40秒的帧被丢弃,只有超出第40秒的帧被显示给用户。

The seeking is still done at the closest key frame since otherwise you will see green patches or pixelation of the video which is highly undesirable. So instead the seeking is done to the key frame and then frames are decoded until the required time but these frames are dropped and are not shown to the user. In above example, all the decoded frames from the 35th to 40th second are discarded and only the frames beyond 40th sec are shown to the user.

在音频的情况下,只有文件有可能出现两种情况(如果没有分析器或解析器,不列入建设中的时间戳表,然后 - )

In case of audio only files there can be two cases (If there is no parser or a parser that doesnot build the timestamp table then -)

CBR - 恒定比特率 - 由于比特率是恒定的,我们可以跳过的字节数必须给定的时间(比特率* timeToSeek =字节被跳过)

CBR - Constant Bit Rate - Since the bit rate is constant we can skip necessary number of bytes to a given time (Bitrate * timeToSeek = bytes to be skipped)

VBR - 可变比特率 - 比特率是不固定它不断变化的。因此,在这种情况下,找出文件的平均位速率,然后使用上述方法,在这种情况下,求将不准确。

VBR - Variable Bit rate - The bit rate is not constant it keeps varying. So in this case the find out the average bitrate of the file and then use the above method, in this case seeking will not be accurate.

现在回到你的问题,我可以告诉大家有信心,它工作得很好,是准确的为广大mediafiles的。

Now coming back to your question, I can tell with confidence that it works well and is accurate for the majority of the mediafiles.

为什么你可能面临此类问题的唯一原因是监守媒体文件本身损坏。 (这只是不可能有30秒的差异在寻求+你说的时间是不正确返回,而且没有任何的媒体播放器API的破碎为Android 2.2)

The only reason why you could be facing such issues is becuase the media file is itself corrupted. (It is just not possible to have a difference of 30seconds during seek + you are saying the duration is not returned correctly. And none of the mediaplayer API's are broken for Android 2.2)

至于哪些格式支持的Andr​​oid见

As to which formats is supported by Android see this link

所以,可以尝试用另一种MP3文件?

So can you try with an another mp3 file?