• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Getting duration of an audio file
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Getting duration of an audio file
      • From: Doug Wyatt <email@hidden>
  • Prev by Date: Re: Custom sub control type
  • Next by Date: Re: Getting duration of an audio file
  • Previous by thread: Re: Custom sub control type
  • Next by thread: Re: Getting duration of an audio file
  • Index(es):
    • Date
    • Thread