Android MediaExtractor seek() accuracy with MP3 audio files

馋奶兔 提交于 2020-01-02 18:04:07

问题


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:

  1. call setDataSource() and selectTrack()
  2. call seekTo()
  3. 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 or SEEK_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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!