开发者

Finding out estimated duration of a stream using Core Audio

开发者 https://www.devze.com 2022-12-24 12:14 出处:网络
I am streaming a MP3 over network using custom feeding code, not AVAudioPlayer (which only works with URLs) using APIs like AudioFileStreamOpen and etc.

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 kn开发者_运维百科ow 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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号