Hi guys,  I’ve been on this list for years, and just realised you may be able 
to help me out with a hellish bug in my app.
I have a problem with AVAudioRecorder

We have an app which works perfectly fine on all our devices, and in the 
simulator, but the client gets a crash EVERY time he tries to record audio. It 
seems like the audio is corrupted or a threading issue, as it passes all other 
checks.

Could you please tell me if there is anything fundamentally wrong I’m doing in 
the use of AVAudioRecorder.

I am using two instances of AVAudioRecorder, one for metering, one for 
recording.

1) App starts, AVAudioSession with record option set. Metering AVAudioRecorder 
instantiated.
2) Client presses record (I’m assuming I don’t have to create another Session 
as we already have one open for the metering), a Record AVAudioRecorder 
instantiated, which is reused for subsequent recordings. 

Is using two instances of AVAudioRecorder a potential problem?
Is reusing the recording instance  a potential problem, should I be releasing 
the previously used one and instantiating a new one each time the client 
presses ‘record’?
Any reason why data has not been fully written to file by the time the 
completionBlock is called?
Any potential background processes running on his Mac which would compile the 
project differently than all the other systems we have successfully ran it on?

Any ideas welcome I’m at a total loss.

-(void)audioRecorderDidFinishRecording: (AVAudioRecorder *)recorder  
successfully:(BOOL)flag{
    
    if(!self.recordCompletionBlock ){
        return;
    }
    
    NSString * filePath = [recorder.url.path copy];
    NSData *data = [[NSFileManager defaultManager] contentsAtPath:filePath];
    
    [self.audioRecorder deleteRecording];
    
    if(!data || !flag || !(data.length>0)){
        DLog(@"Problem accessing recording data at path %@", filePath );
        NSError * error = [VVErrorFactory createErrorWithDescription:@"No audio 
data at stopRecordingAudioAtFilePath" code:GENERAL_ERROR fromInstance:self];
        self.recordCompletionBlock(nil , error);
        return ;
    }
    
 
    //
    NSString *UUID = [[NSUUID UUID] UUIDString];
    NSString * fileNameString = [UUID stringByAppendingString:@".caf"];
    NSString *soundFilePath = [self.directory  
stringByAppendingPathComponent:fileNameString];
    
    if(![data writeToFile:soundFilePath atomically:YES]){
        DLog(@"Problem accessing recording data at path %@", filePath );
        NSError * error = [VVErrorFactory createErrorWithDescription:@"No audio 
data at stopRecordingAudioAtFilePath" code:GENERAL_ERROR fromInstance:self];
        self.recordCompletionBlock(nil , error);
        return ;
    }
 
    [self.audioRecorder prepareToRecord];
    self.recordCompletionBlock(soundFilePath , nil);
}
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/coreaudio-api/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to