开发者

iPhone - get duration of linear PCM audio file

I have a linear PCM file (.wav) in my app and I would like to get it's dur开发者_Python百科ation 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.


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


Using AudioFile kAudioFilePropertyEstimatedDuration property is best, however if you want the math for PCM: duration = totalNumPackets * ASBD.mFramesPerPacket / ASBD.mSampleRate

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜