2012-10-15 22 views
-1

我想拍一張照片,一旦我這樣做,音頻就會自動開始錄製,例如3秒鐘。使用定時器進行錄音

這3秒鐘應該被定時器倒計數,在拍攝照片後出現在屏幕的左側。

這樣,那我不得不圖像和聲音結合在一起並將其保存在一個私有目錄

有人能告訴我我如何使用AVFoundation音頻工具箱框架做到這一點?

+0

歡迎來到Stack Overflow。請花些時間閱讀[常見問題](http://stackoverflow.com/faq),特別是提問問題。請記住,我們在這裏幫助,而不是爲你做你的工作。 –

回答

1

我通常不會與AVFoundation一起工作,所以我不知道確切的方法/類名(我自己填寫),但解決方法是從錄製最初開始時開始重複使用NSTimer。事情是這樣的:

@interface 
int rec_time; 
NSTimer *timer; 
Recorder *recorder; 
@end 

@implementation 
-(void)beginRecording { 
    [recorder startRecording]; 
    timer = [NSTimer scheduledTimerWithTimeInterval:1.0 
    target:self 
    selector:@selector(recordingTime) 
    userInfo:nil 
    repeats:YES]; 
} 

-(int)recordingTime { 
    if (rec_time >= 10) { 
     [recorder endRecording]; 
     [timer invalidate]; 
     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"You recorded for too long!"; 
     return; 
    } 

    rec_time = rec_time + 1; 

} 
@end 

而且

AVAudioRecorder有以下方法:

- (BOOL)recordForDuration:(NSTimeInterval)duration 

我認爲,將這樣的伎倆!

http://developer.apple.com/library/ios/#documentation/AVFoundation/Reference/AVAudioRecorder_ClassReference/Reference/Reference.html#//apple_ref/doc/uid/TP40008238

+0

非常感謝......這僅適用於在NSTimer到位的情況下錄製音頻。我如何將拍攝的圖像和錄製的音頻合併到單個文件中?此外,我不希望它被保存在默認目錄中,但在我的私人目錄。 –

相關問題