如何在iphone上设置录音电平表?

时间:2013-01-07 09:57:14

标签: iphone objective-c ios audio-recording

录制声音时,我使用以下代码:

- (IBAction) recordClicked:(id)sender {
    NSLog(@"play Record");
    if (audioPlayerRecord) {
        if (audioPlayerRecord.isPlaying) [audioPlayerRecord stop];
        else {
            [audioPlayerRecord play];
            [self updateCurrentTimeForPlayer:audioPlayerRecord];
        }
        return;
    } 

    //Initialize playback audio session
    AVAudioSession *audioSession = [AVAudioSession sharedInstance];
    [audioSession setCategory:AVAudioSessionCategoryPlayback error:nil];

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *recDir = [paths objectAtIndex:0];
    NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/recordTest.caf", recDir]];

    NSError *error;
    audioPlayerRecord = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
    [audioPlayerRecord play];
    duration.text = [NSString stringWithFormat:@"%d:%02d", (int)audioPlayerRecord.duration / 60, (int)audioPlayerRecord.duration % 60, nil];
    progressBar.maximumValue = audioPlayerRecord.duration;
    [self updateViewForPlayerState:audioPlayerRecord];
    NSLog(@"Recoder file >");
}

当正在进行录制时,我想显示以下类型的电平表

Level meter

那么还有其他简化方法可以解决这个问题吗?

1 个答案:

答案 0 :(得分:0)

检查AQRecorder.mm ......

查找:void AQRecorder::StartRecord(CFStringRef inRecordFile)

在这里你必须评论/删除de line

url = CFURLCreateWithString(kCFAllocatorDefault, (CFStringRef)recordFile, NULL);

url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, (CFStringRef)recordFile, kCFURLPOSIXPathStyle, false);