Getting duration of an audio file
Getting duration of an audio file
- Subject: Getting duration of an audio file
- From: Peter Ammon <email@hidden>
- Date: Wed, 27 Jul 2005 15:49:44 -0700
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