问题
I am having trouble getting reasonable accuracy on seek() with Android MediaExtractor
. For some files, such as this one, I find significant inaccuracies (about 3 seconds in this case.) I have the following flow:
- call
setDataSource()
andselectTrack()
- call
seekTo()
- call
play()
In this case, it seeks to an incorrect position, but reports the correct position. If I then seek to another position, it continues to be off by the same margin. However, if I seek to 0, it corrects itself, and then will seek to the correct location in the file.
Is this simply a limitation / bug in MediaExtractor? Does anyone have a fix / workaround to get more accuracy? I would prefer not to start playback at position 0 before seeking, but I suppose that is one option.
Some other notes:
- Android MediaPlayer shows the same behavior.
- This happens whether I select
MediaExtractor.SEEK_TO_PREVIOUS_SYNC
orSEEK_TO_CLOSEST_SYNC
- I see the same problem on KitKat and Lollipop, on the emulator and physical devices.
- A quick analysis of one failed file showed "Wrong number of MPEG data bytes specified in Xing header," but I got the same result for files that played fine.
来源:https://stackoverflow.com/questions/30401733/android-mediaextractor-seek-accuracy-with-mp3-audio-files