2011-01-07 3 views
5

(목표 C) 간단한 AudioServicesPlaySystemSoundID 및 그 대응 부분을 사용하기 만하지만 오디오 파일의 길이를 찾는 방법이 이미있는 경우 문서에서 찾을 수 없습니다. .오디오 파일의 길이를 찾는 방법 (초 단위)

AudioServicesGetPropertyInfo가 있습니다.하지만 바이트 버퍼를 반환하는 것으로 보입니다. 오디오 파일이 자신의 길이를 포함하고 있으며 이것으로 추출 할 수 있습니까?

또는 비트 전송률 * fileSize를 기반으로 한 수식이 길이로 변환됩니까?

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

당신이 시스템 사운드 서비스를 사용하는 특별한 이유가 :

mIL3S

www.milkdrinkingcow.com

답변

14

빠른 구글 검색에 따르면, 공식이있다 소리 나? AVPlayer를 사용하지 않고 http://developer.apple.com/library/mac/#samplecode/PlayFile/Introduction/Intro.html

:

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

가에서 ADC 샘플을 참조하십시오에서 참조

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

예, AVAudioPlayer를 사용해야한다고 가정합니다. AudioServices가 괜찮 았던 몇 가지 작은 소리를 재생 한 이후로 추측합니다. 이제는 그 정보를 더 필요로하므로 전환해야 할 것입니다. 그래도 공식에 감사드립니다! 나는 그런 것이 있을지 모르지만. mIL3S –

0

: 당신이 당신의 소리를 처리 할 AVAudioPlayer를 사용하는 경우

당신이 뭔가를 할 수 있습니다. ..

+0

그러나 Mac OS X의 경우에만 해당되지 않습니까? 질문은 아이폰으로 태그가 붙어있다. – newenglander

11

nswer How to get the duration of an audio file in iOS?. 이것이 최고의 대답입니다.

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

+0

이것은이 IMO를 달성하는 가장 좋은 방법입니다. – theLastNightTrain