Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Getting duration of an audio file
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Getting duration of an audio file



Here's the code I'm using to get the duration (in seconds) of an audio file:

SInt64 packetCount;
UInt32 dataSize = sizeof packetCount;
OSStatus result = AudioFileGetProperty(audioFile, kAudioFilePropertyAudioDataPacketCount, &dataSize, &packetCount);
if (result==noErr) {
double duration = ((double)packetCount * myASBD.mFramesPerPacket) / myASBD.mSampleRate;
}


Here, myASBD is the AudioStreamBasicDescription for audioFile. Is this code correct? If so, is it exact for variable-bit rate files, or is the calculated duration an estimate? It appears to be exact, but I'd rather be sure.

Thanks,
-Peter
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden




Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.