views:

141

answers:

1

I am streaming a MP3 over network using custom feeding code, not AVAudioPlayer (which only works with URLs) using APIs like AudioFileStreamOpen and etc.
Is there any way to estimate a length of the stream? I know that I can get a 'elapsed' property using:

if(AudioQueueGetCurrentTime(queue.audioQueue, NULL, &t, &b) < 0)
        return 0;

    return t.mSampleTime / dataFormat.mSampleRate;

But what about total duration to create a progress bar? Is that possible?

P.S. Clarification - I do know the actual size of the MP3 file, don't know if that can be used... I'll even settle for solution that just gives me a progress bar, not the actual time of play/duration.

A: 

If you know the total size of the MP3 file, you can calculate the bits per second, and therefore calculate the duration of the stream. If it's VBR, you'll probably have to average several MPEG frames. For CBR, you can simply use the bitrate of one packet.

lucius
yup, that's the solution i went for.
Reflog