简体   繁体   中英

Seeking in an mp3 file

I'm working on mp3 player using java by reading the file, decoding frames and playback audio. However, I want to support my app with seeking. For CBR its easy because I can approximately calculate how much bytes I should skip. For example: seeking 50s with 128 kbps it's approximately (50/0.026)*417 . But that doesn't work with VBR because bitrate is not constant.

Is there any way or method to calculate how many bytes I should skip in VBR without decoding all the frames in the way?

您可以将mp3文件解码为缓冲区,然后从缓冲区进行播放(随时计算帧数)。

I solved my problem by calculating the average bitrate for VBR files. That can be done by dividing the file length in bits on the song duration. avg = size*8/duration then seek as CBR but with calculating the frame size with the average bitrate instead of constant bitrate.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM