Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7734049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:09:11+00:00 2026-06-01T07:09:11+00:00

I got this problem with AVAudioRecorder not working for me, at least from what

  • 0

I got this problem with AVAudioRecorder not working for me, at least from what i can see (or can’t hear).

I am targeting iOS 5 with ARC.

I did setup error objects but none of them get fired, so i guess i am doing something wrong here.

Here is the part were i setup the AVAudioRecorder :

NSArray *dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docsDir = [dirPaths objectAtIndex:0];
NSString *soundFilePath = [docsDir stringByAppendingPathComponent:currentTrack.trackFileName];

currentTrack.trackFileURL = [NSURL fileURLWithPath:soundFilePath];

NSLog(@"Chemin : %@", currentTrack.trackFileURL.path);

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

[recordSetting setValue :[NSNumber numberWithInt:kAudioFormatLinearPCM] forKey:AVFormatIDKey];
[recordSetting setValue:[NSNumber numberWithFloat:44100.0] forKey:AVSampleRateKey]; 
[recordSetting setValue:[NSNumber numberWithInt: 2] forKey:AVNumberOfChannelsKey];

[recordSetting setValue :[NSNumber numberWithInt:16] forKey:AVLinearPCMBitDepthKey];
[recordSetting setValue :[NSNumber numberWithBool:NO] forKey:AVLinearPCMIsBigEndianKey];
[recordSetting setValue :[NSNumber numberWithBool:NO] forKey:AVLinearPCMIsFloatKey];


currentTrack.trackRecordSettings = recordSetting;


NSError *err = nil;


//[audioSession setDelegate:self];
if(err){
    NSLog(@"audioSession: %@ %d %@", [err domain], [err code], [[err userInfo] description]);
    return;
}
[[AVAudioSession sharedInstance] setActive:YES error:&err];
err = nil;
if(err){
    NSLog(@"audioSession: %@ %d %@", [err domain], [err code], [[err userInfo] description]);
    return;
}
err = nil;
recorder = [[AVAudioRecorder alloc]
                 initWithURL:currentTrack.trackFileURL
                 settings:currentTrack.trackRecordSettings
                 error:&error];

if (err)
{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle: @"Warning"
                               message: [err localizedDescription]
                              delegate: nil
                     cancelButtonTitle:@"OK"
                     otherButtonTitles:nil];
    [alert show];
    NSLog(@"error: %@", [error localizedDescription]);

} else {
    [recorder setDelegate:self];
    [recorder prepareToRecord];

    BOOL audioHWAvailable = [[AVAudioSession sharedInstance]inputIsAvailable ];
    if (!audioHWAvailable) {
        UIAlertView *cantRecordAlert =
        [[UIAlertView alloc] initWithTitle: @"Warning"
                                   message: @"Audio input hardware not available"
                                  delegate: nil
                         cancelButtonTitle:@"OK"
                         otherButtonTitles:nil];
        [cantRecordAlert show]; 
        return;
    }
}

No error thrown here

Then when it is time to start the recording :

-(void)startRecordingAudio{
    NSLog(@"Start recording");
    [[AVAudioSession sharedInstance] setCategory :AVAudioSessionCategoryRecord error:nil];
    [recorder record];
}

Then when it is time to stop the recording :

-(void)stopRecordingAudio{
    NSLog(@"Stop recording");
    [recorder stop];
    NSError *err;
    NSData *audioData = [NSData dataWithContentsOfFile:currentTrack.trackFileURL.path options: 0 error:&err];
    if(!audioData)
        NSLog(@"audio data error: %@ %d %@", [err domain], [err code], [[err userInfo] description]);
    NSLog(@"%d", audioData.length);
    }

Is it normal that audioData length is always 4096 ? If i understand right it is about 93 ms of sound…

Finally, when it is time to play the recorded sound:

-(void)startPlayingAudio{
    [[AVAudioSession sharedInstance] setCategory :AVAudioSessionCategoryPlayback error:nil];

    NSLog(@"Start playing");
    NSError *error;
    if(player == nil){
        player = [[AVAudioPlayer alloc] initWithContentsOfURL:currentTrack.trackFileURL    
        error:&error];                                                                           
    }


    player.delegate = self;

    if (error)
        NSLog(@"Error: %@", 
              [error localizedDescription]);
    else
        [player  play];
}

I did setup delegate methods that never fire too :

-(void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag
{
   NSLog (@"audioRecorderDidFinishRecording:successfully:");
}
-(void)audioPlayerDecodeErrorDidOccur:(AVAudioPlayer *)player error:(NSError *)error
{
    NSLog(@"Decode Error occurred");
}
-(void)audioRecorderDidFinishRecording:(AVAudioRecorder *)recorder successfully:    (BOOL)flag
{
    NSLog (@"audioRecorderDidFinishRecording:successfully: %d", flag);
}
-(void)audioRecorderEncodeErrorDidOccur:(AVAudioRecorder *)recorder error:(NSError *)error
{
    NSLog(@"Encode Error occurred");
}
-(void)beginInterruption{
    NSLog(@"INTERRUPT");
}

Also, i did see that the .caf file are created correctly in my app document folder.

Thanks for any help you can bring. As for now i cannot hear the sound recorded and i test using iPhone 4 device with no headphones.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T07:09:12+00:00Added an answer on June 1, 2026 at 7:09 am

    Found the problem :
    record was called before prepareRecord. Since i was using viewDidAppear to setup the recording, the call to start the recording was made before the view was visible…

    I did use viewDidAppear because viewDidLoad is not called since i dont use initWithNib. I tried to override loadView, but all the examples i found are not that clear about the subject and loadView is never called. Maybe somebody can point me into the right direction? Nonetheless, i can hear my voice on the iphone!

    Thanks for your time.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got this nasty problem where sending multiple, large messages in quick succession from
I got this problem from an interview with Microsoft. Given an array of random
I've got this problem and I can't for the life of me find a
I've got this problem that I can't solve. Partly because I can't explain it
I've got this problem with completed events not firing for WCF long running calls
I got this problem that I can't just solve algorithmically. Let's say i have
I've got this problem.. it's soon not problem, but i want not to use
I got this problem 'UINT64_C' was not declared in this scope while using the
I got this problem: invalid conversion from ‘void*’ to ‘uint8_t*’ When doing this: int
Ive got this problem: Line 20 (LOOT_FromContainer(container) I need that to use as Invoke

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.