How to find the length of the audio file (in seconds)

(Goal C) Just using a simple AudioServicesPlaySystemSoundID and its analogs, but I can not find in the documentation if there is a way to find the length of the audio file.

I know there is AudioServicesGetPropertyInfo, but it looks like it returns a byte buffer - the audio files insert their length by themselves, and can I just extract it with this?

Or is there perhaps a formula based on the * fileSize bit rate for conversion to duration?

mIL3S

www.milkdrinkingcow.com

+5
source share
3 answers

According to a quick Google search, there is a formula:

length-of-time (duration in seconds) = fileSize (in bytes) / bit-rate (bits/secs)*8

- , System Sound Services ?

AVAudioPlayer , - :

AVAudioPlayer * sound = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:nil];
sound.delegate = self;
sound.volume = 1;
NSLog([NSString stringWithFormat:@"%f", sound.duration]);
+15

iOS?. .

AVURLAsset* audioAsset = [AVURLAsset URLAssetWithURL:audioFileURL options:nil]; CMTime audioDuration = audioAsset.duration; float audioDurationSeconds = CMTimeGetSeconds(audioDuration);

+11

. :

Float64 fileDuration = PrepareFileAU (fileAU, fileFormat, audioFile);

. ADC: http://developer.apple.com/library/mac/#samplecode/PlayFile/Introduction/Intro.html

AVPlayer...

0

All Articles