I want to download song from server, but I don't want to download the whole song, so I'd like to download the first 90‘s ,if user listen the first 80's, I will request the rest of this song. otherwise the rest of this song is unnecessary to download at all.
The request header has a range
parameter,I can pass the min - max byte to decide which piece of song I should download.
So, How can I know how many bytes of a song can play 90's??
At it's simplest you need to know the bit rate of the encoded file (which you can get by reading the file header) and then multiply to get the number of bytes however many MP3s are encoded with a variable bit rate, which as Matt said in his comment, makes the solution very complex.
However, if you change your approach slightly you can achieve something similar in a much simpler way - rather that worry about a certain length of time, just read a number of bytes
Simply pick a reasonable number of bytes to read initially and when you are close to exhausting this data read the remainder of the file.
1 megabyte gets you a little more than 60 seconds of an MP3 file encoded with a fixed bit rate of 128kbs - It will get you about 30 seconds of a fixed bit rate 256kbs file and somewhere between 30-60 seconds if it is variable bit rate (VBR), so this seems like a reasonable amount to read initially.