2012-03-19 8 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

+0

AVFoundation Framework – user1120133

答えて

1

あなたがAVAudioPlayerを使用している場合、あなたはそれが数秒でロードされたオーディオファイルの長さを取得するためにdurationプロパティの使用することができます。

1

http://developer.apple.com/library/ios/#codinghowtos/AudioAndVideo/_index.html https://developer.apple.com/library/mac/#documentation/musicaudio/reference/AudioFileConvertRef/Reference/reference.html

EDIT。これらのリンクを参照してください。詳細は

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); 

... AudioFileServices機能を使用します。これは、それが関連付けられていない場合でも、ファイルの長さを取得することですAVPlayer ..あなたはリストを作成することができます...これは誰かに役立つことを期待..:D

関連する問題