Seek to a position in an Audio file

I have my audio files playing correctly now. (Yay!) and now I need to implement my slider to let the user skip and and rewind the audio.

I see a routine named AudioQueueDeviceGetCurrentTime which will be great for telling me where I am, but I don't see a corresponding SET routine.

Is there an API for skipping around an audio file?

Thanks!

MacBookPro, Mac OS X (10.5.5)

Posted on Sep 27, 2008 12:19 PM

Reply
7 replies

Sep 29, 2008 3:25 PM in response to Mike Marcoe

You don't need to know that, you simply need to sample rate and the frames per packet. From there you can calculate what your packet offset from the beginning of the file should be. If you do all the calculations up front before you begin playing, compressed vs non-compressed will make no difference when you are figuring the number of packets to skip.

Oct 14, 2008 5:16 PM in response to Xanthos

Sorry for the delay, I've been away from the code a bit.

I followed your advice, it makes sense. My test audio file is 2400 packets long. So when I slide my slider I can just set my packet to read to the appropriate value.

The problem is that I crash now!

So I tried setting my my current packet to, say 700 packets, in on the FIRST time I play the audio file. Crash city!

I first set this up by calling:

startingPacketNumber = inNumPackets;

in my AudioQueueObject.

Then I do the normal setting up of the 3 buffers, calling my playbackCallback on each to fill the buffer.


int current = [player startingPacketNumber];
// current = 700, not 0

AudioFileReadPackets (
[player audioFileID],
NO,
&numBytes,
[player packetDescriptions],
current,
&numPackets,
bufferReference->mAudioData
);

AudioFileReadPackets crashes on the first time it is called.

I'm at a loss here. I appreciate any help. I can show more code but the above should look familiar, it is pretty much straight from the audio sample.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Seek to a position in an Audio file

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.