How to check current time and duration in AudioQueue

后端 未结 3 1391
隐瞒了意图╮
隐瞒了意图╮ 2021-02-06 13:31

How to get total time duration of music in audioQueue. I am using

NSTimeInterval AQPlayer::getCurrentTime()
{
    NSTimeInterval timeInterval =         


        
3条回答
  •  攒了一身酷
    2021-02-06 13:40

    AudioQueueGetCurrentTime(mQueue, timeLine, &timeStamp, NULL); for getting current playing time, it gives some large value is it valid

    Probably, but it's not what you think. It's not in seconds; the docs don't really say what it is in, but Googling around, it appears to be in frames, for whatever reason. (For one example, this technote includes a snippet that treats it as frames.) Try dividing by the sample rate and dividing by the (source's) frame rate, and see which one gets you sane numbers.

    how to get duration of music file.

    There isn't one. An audio queue is just that: a queue of audio samples to be played or recorded. The only length the queue has is the number of samples you can have queued in it; the queue does not know the length of anything that might be feeding into it, if those sources even have a finite length.

    The audio queue calls a function you create to get the audio samples from you. Wherever your function gets the samples from (e.g., an AudioFile) is where you need to get the length from. If you're generating the samples yourself (as in a tone or noise generator), then the length, if any, is up to you.

提交回复
热议问题