AVAudioRecord prepareRecord & Record возвращает НЕТ

В настоящее время я работаю над игровым проектом, который поддерживает запись звука. эта программа основана на WiEngine, игровом движке вроде cocos2d-x.

вот в чем дело, я пробовал много способов, но КАЖДЫЙ раз, когда я вызывал [myRecorder Record], он всегда возвращает НЕТ. затем я явно вызвал PrepareRecord, он также возвращает No.

вот код, как я запускаю рекордер

- (void)initRecorder
{
    if(self.myRecoder!=nil)
    {
        [self.myRecoder release];
        self.myRecoder=nil;
    }


    NSDictionary *myRecorderParam = [[NSDictionary alloc]initWithObjectsAndKeys:
                                     [NSNumber numberWithFloat:44100.0],AVSampleRateKey,
                                     [NSNumber numberWithInt:kAudioFormatLinearPCM],AVFormatIDKey,
                                     [NSNumber numberWithInt:16],AVLinearPCMBitDepthKey,
                                     [NSNumber numberWithInt:1],AVNumberOfChannelsKey,
                                     [NSNumber numberWithInt:AVAudioQualityMedium],AVEncoderAudioQualityKey,
                                     nil];

    NSArray *pathArray = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

    NSString *DocumentPath = [pathArray objectAtIndex:0];
    DocumentPath = [DocumentPath stringByAppendingString:@"/luyin.wav"];

    self.myRecoder = [[AVAudioRecorder alloc]initWithURL:[NSURL URLWithString:DocumentPath]
                                                settings:myRecorderParam
                                                   error:nil];


    [self.myRecoder setDelegate:self];

}

и я позвонил в Record так

- (void)beginRecord
{
    NSLog(@"begin record");

//    AVAudioSession *audioSession = [AVAudioSession sharedInstance];
//    NSError *err = nil;
//    [audioSession setCategory :AVAudioSessionCategoryPlayAndRecord error:&err];
//    if(err){
//        NSLog(@"audioSession: %@ %d %@", [err domain], [err code], [[err userInfo] description]);
//        return;
//    }
//    err = nil;
//    [audioSession setActive:YES error:&err];
//    if(err){
//        NSLog(@"audioSession: %@ %d %@", [err domain], [err code], [[err userInfo] description]);
//        return;
//    }

    if(self.myRecoder==nil)
    {
        NSLog(@"recoder null");
    }

    BOOL resultPre = [[self myRecoder] prepareToRecord];
    if(resultPre)
    {
        NSLog(@" record pre yes ");
    }
    else
    {
        NSLog(@" record pre no ");
    }

    BOOL result = [[self myRecoder] record];
    if(result)
    {
        NSLog(@" record yes ");
    }
    else
    {
        NSLog(@" record no ");
    }
}

судя по NSLogs, я уверен, что инициализация вроде бы не провалилась.

Я также пытался запустить AudioSession , но он тоже не работает.

ПОЖАЛУЙСТА ПОМОГИ


person Lorin    schedule 29.07.2013    source источник


Ответы (1)


это AVAudioRecorder?

AVAudioPlayer используется для записи воспроизведения

Нравится:

NSMutableDictionary* recordSetting = [[NSMutableDictionary alloc] init];

[recordSetting setValue: [номер NSNumberWithInt:kAudioFormatAppleIMA4] forKey:AVFormatIDKey];

[recordSetting setValue:[NSNumber numberWithFloat:[freq.text floatValue]] forKey:AVSampleRateKey];
[recordSetting setValue:[NSNumber numberWithInt: [value.text intValue]] forKey:AVNumberOfChannelsKey];

записанныйTmpFile = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent: [NSString stringWithFormat: @"%.0f.%@", [NSDate timeIntervalSinceReferenceDate] * 1000.0, @"caf"]]]];
NSLog(@"Using File вызвано: %@",recordedTmpFile);
рекордер = [[ AVAudioRecorder alloc] initWithURL:recordedTmpFile settings:recordSetting error:&error];

person Susu    schedule 29.07.2013
comment
Извините, я вставил другой код. теперь я его отредактировал, это AVAudioRecorder - person Lorin; 29.07.2013