2012-03-19 101 views
1

如何找到音頻文件播放的總時間長度,以便我可以根據時間編程在視頻控制器中顯示音頻文件的內容。音頻文件的長度

if ([audioPlayer currentTime] ==11){ 
    [self performSelector:@selector(viewController) withObject:nil]; 

    } else { 

     if ([audioPlayer currentTime] ==23){ 
      [self performSelector:@selector(secondViewController) withObject:nil]; 

     } 
+0

你使用什麼框架? – esqew 2012-03-19 19:45:19

+0

AVFoundation框架 – user1120133 2012-03-19 19:46:07

回答

1

使用AudioFileServices功能...

NSURL *afUrl = [NSURL fileURLWithPath:soundPath]; 
AudioFileID fileID; 
OSStatus result = AudioFileOpenURL((CFURLRef)afUrl, kAudioFileReadPermission, 0, &fileID); 
UInt64 outDataSize = 0; 
UInt32 thePropSize = sizeof(UInt64); 
result = AudioFileGetProperty(fileID, kAudioFilePropertyEstimatedDuration, &thePropSize, &outDataSize); 
AudioFileClose(fileID); 

更多信息請參考以下鏈接.. http://developer.apple.com/library/ios/#codinghowtos/AudioAndVideo/_index.html https://developer.apple.com/library/mac/#documentation/musicaudio/reference/AudioFileConvertRef/Reference/reference.html

編輯:這是獲得哪怕是沒有關聯的文件的長度AVPlayer ..所以你可以填充一個列表...希望這可以幫助某人..:D