R – iPhone – get duration of linear PCM audio file

core-audioiphone

I have a linear PCM file (.wav) in my app and I would like to get it's duration programatically. I could find the following using AudioStreamBasicDescription but could not make out how to get the duration in seconds.

mFormatID
mSampleRate
mChannelsPerFrame
mBytesPerPacket
mFramesPerPacket
mBytesPerFrame
mBitsPerChannel

Can someone please tell me how I can get the duration.

Thanks.

Best Answer

You can create an AVAudioPlayer instance with your file. AVAudioPlayer has duration property.