1

我想知道我的错误,或者我是否忘记了代码中的某些内容......

-(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 或更低,它将播放录制的文件......现在,我的问题是当我录制超过 5 次时,我的我现在无法听到我的录音文件,我不知道是什么问题..请帮助..我完全没有...

4

0 回答 0