Seeking in an mp3 file

Majd :

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?

Majd :

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.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=84176&siteId=1