1

I am trying to make a voice recorder which behaves as following

  1. Record voice
  2. Pause the voice
  3. Listen to the recording
  4. Continue Recording

I tried doing this:

Initialize the Recorder

NSString *cacheDir = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];
NSString *dataPath = [cacheDir stringByAppendingPathComponent:@"/AudioFiles"];
if (![[NSFileManager defaultManager] fileExistsAtPath:dataPath])
{
    NSError *error=nil;
    [[NSFileManager defaultManager] createDirectoryAtPath:dataPath withIntermediateDirectories:NO attributes:nil error:&error];
}
NSArray *pathComponents = [NSArray arrayWithObjects:
                           dataPath,
                           [NSString stringWithFormat:@"%@.m4a",self.FileName],
                           nil];
NSURL *outputFileURL = [NSURL fileURLWithPathComponents:pathComponents];

// Setup audio session
AVAudioSession *session = [AVAudioSession sharedInstance];
[session setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];
// Define the recorder setting
NSMutableDictionary *recordSetting = [[NSMutableDictionary alloc] init];

[recordSetting setValue:[NSNumber numberWithInt:kAudioFormatMPEG4AAC] forKey:AVFormatIDKey];
[recordSetting setValue:[NSNumber numberWithFloat:22050.0] forKey:AVSampleRateKey];
[recordSetting setValue:[NSNumber numberWithFloat:32000.0] forKey:AVEncoderBitRateKey];
[recordSetting setValue:[NSNumber numberWithInt: 1] forKey:AVNumberOfChannelsKey];
[recordSetting setValue:AVAudioBitRateStrategy_Variable forKey:AVEncoderBitRateStrategyKey];
// Initiate and prepare the recorder
recorder = [[AVAudioRecorder alloc] initWithURL:outputFileURL settings:recordSetting error:NULL];
recorder.delegate = self;
recorder.meteringEnabled = YES;
[recorder prepareToRecord];

Record

[recorder record];

Pause the record

[recorder pause];

Play the record

playingSession = [AVAudioSession sharedInstance];
[playingSession setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];
[playingSession setActive: YES error:nil];
NSError *error = nil;
player = [[AVAudioPlayer alloc] initWithContentsOfURL:recorder.url error:&error];
NSLog(@"Error initializing player: %@", error);
[player setDelegate:self];
[player play];

So I get the following error

Error Domain=NSOSStatusErrorDomain Code=1685348671 "(null)"

Any idea how can I make this work?

Ali
  • 497
  • 1
  • 4
  • 16
  • Follow this: http://stackoverflow.com/questions/11009975/play-a-paused-avaudiorecorder-file and http://stackoverflow.com/questions/11667241/how-to-pause-and-resume-audio-recording-using-avaudiorecorder – Jamshed Alam Oct 31 '16 at 15:54

0 Answers0