エラーを知りたい、またはコードで何かを忘れていないか...
-(IBAction)playRecord
{
NSLog(@"stop rec");
[recorder stop];
[self playSound];
}
-(void)playSound{
NSLog(@"play");
recorderFilePath = [NSString stringWithFormat:@"%@/MySound.caf", DOCUMENTS_FOLDER];
NSURL *urlRecord = [NSURL fileURLWithPath:recorderFilePath isDirectory:NO];
NSError *errorRecord;
soundRecord = [[AVAudioPlayer alloc] initWithContentsOfURL:urlRecord error:&errorRecord];
[soundRecord prepareToPlay];
[soundRecord play];
soundRecord.delegate = self;
[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(stopPlayRec) userInfo:nil repeats:YES];
}
-(void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag
{
[recorder prepareToRecord];
[recorder record];
NSLog(@"Finish");
}
-(void)stopPlayRec
{
if ([recorder peakPowerForChannel:(0)] <= (-30) && [recorder peakPowerForChannel:(0)] >= (-43))//detecting voice then record
{
NSLog(@"test");
[self playRecord];
}
else
{
if ([recorder peakPowerForChannel:(0)] >= (-160))
{
NSLog(@"playing");
}
}
}
私viewdidload
はすでに「録音開始」機能を初期化していますが、
[self startRecording];
そのため、ビューがロードされた瞬間に記録が開始されます..次に、再生ボタンを押すと、記録されたファイルが再生されます.コードの流れは、再生ボタンを押した後です. PeakPowerForChannel が -30 から -43 (音声を検出) である場合、PeakPowerChannel が -160 以下の場合、録音されたファイルを再生します。録音ファイルを聞くことができませんでした。何が問題なのかわかりません..助けてください..まったく初心者です...