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 6381955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:27:37+00:00 2026-05-25T02:27:37+00:00

I need to record audio stream with iPhone mic. I am using AVAudioRecorder from

  • 0

I need to record audio stream with iPhone mic.
I am using AVAudioRecorder from this thing.

I initialize AVAR in init:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *cachePath = [[paths objectAtIndex:0] retain];
NSError *error;
BOOL isDir = NO;
if (! [[NSFileManager defaultManager] fileExistsAtPath:cachePath isDirectory:&isDir] && isDir == NO) {
    [[NSFileManager defaultManager] createDirectoryAtPath:cachePath withIntermediateDirectories:NO attributes:nil error:&error];
}

pathNewFile=  [cachePath stringByAppendingPathComponent:@"123.caf"];

NSLog(@"%@",pathNewFile);

NSDictionary *settings=[[NSDictionary alloc]initWithObjectsAndKeys:
                               [NSNumber numberWithFloat:44100.0f],AVSampleRateKey,
                                    [NSNumber numberWithInt:kAudioFormatAppleLossless],AVFormatIDKey,
                                    [NSNumber numberWithInt:1],AVNumberOfChannelsKey,
                                    [NSNumber numberWithInt:AVAudioQualityMax],AVEncoderAudioQualityKey, nil];
recorder=[[AVAudioRecorder alloc] initWithURL:[NSURL URLWithString:pathNewFile] settings:settings error:nil];
[recorder prepareToRecord];

And I start recording when user presses the rec-button:

-(void)recButton:(id)sender{
    NSLog(@"start rec");
        [rootNotesButton setTitle:@"Stop" forState:UIControlStateNormal];
            [rootNotesButton removeTarget:self action:@selector(recButton:) forControlEvents:UIControlEventTouchUpInside];
            [rootNotesButton addTarget:self action:@selector(stopButton:) forControlEvents:UIControlEventTouchUpInside];
            [recorder record];
}

-(void)stopButton:(id)sender{
            NSLog(@"stop rec");
            [rootNotesButton setTitle:@"Play" forState:UIControlStateNormal];
            [rootNotesButton removeTarget:self action:@selector(stopButton:) forControlEvents:UIControlEventTouchUpInside];
            [rootNotesButton addTarget:self action:@selector(playButton:) forControlEvents:UIControlEventTouchUpInside];
            [recorder stop];
}

-(void)playButton:(id)sender{
        NSLog(@"play rec");
            [rootNotesButton setTitle:@"Stop" forState:UIControlStateNormal];
            [rootNotesButton removeTarget:self action:@selector(playButton:) forControlEvents:UIControlEventTouchUpInside];
            [rootNotesButton addTarget:self action:@selector(stopPButton:) forControlEvents:UIControlEventTouchUpInside];

            player=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL URLWithString:pathNewFile] error:nil];
            [player play];
}

-(void)stopPButton:(id)sender{
        NSLog(@"Stop play");
            [rootNotesButton setTitle:@"Play" forState:UIControlStateNormal];
            [rootNotesButton removeTarget:self action:@selector(stopPButton:) forControlEvents:UIControlEventTouchUpInside];
            [rootNotesButton addTarget:self action:@selector(playButton:) forControlEvents:UIControlEventTouchUpInside];
            [player stop];
}

But when I try to run my project in simulator: My debugger stops on string:
recorder=[[AVAudioRecorder alloc] initWithURL:[NSURL URLWithString:pathNewFile] settings:settings error:nil]; Without any signal or error.

  • 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-05-25T02:27:38+00:00Added an answer on May 25, 2026 at 2:27 am

    The problem seems to be with writing to cachePath in the Simulator. I tried this and it worked:

    #if TARGET_IPHONE_SIMULATOR
        NSString *cachePath = @"/tmp";
    #else
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
        NSString *cachePath = [[paths objectAtIndex:0] retain];
    #endif
    

    You have a couple memory leaks:

    1. You are retaining cachePath but not releasing it. There’s actually no reason to retain it in the first place.

    2. You are creating player with +alloc/-init in playButton which means you own it but you are not releasing it (at least not in the posted code). If you are defining it as a property you need to use self.player = … in order for it to be properly retained and released.

    3. You are creating settings with +alloc/-init but not releasing it. There’s no reason to do that. You can create it like this instead:

    NSDictionary *settings=[NSDictionary dictionaryWithObjectsAndKeys:
    [NSNumber numberWithFloat:44100.0f],AVSampleRateKey,
    [NSNumber numberWithInt:kAudioFormatAppleLossless],AVFormatIDKey,
    [NSNumber numberWithInt:1],AVNumberOfChannelsKey,
    [NSNumber numberWithInt:AVAudioQualityMax],AVEncoderAudioQualityKey, nil];

    You need to retain pathNewFile because stringByAppendingPathComponent returns an autoreleased string and you are using it in other methods of your class.

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

Sidebar

Related Questions

I need to record audio clips from web browser using flash and store them
I am trying to record audio using an iPhone app and send the audio
I currently use AudioRecord to record audio in from the mic of an Android
I need to find the best way to record an audio stream. I have
I need to retrieve a record from a database, display it on a web
I need to get only 1 record from sql result. we use SELECT TOP
I need to record audio and video files to the 3gp/mp4 format in the
I want to make a program that would record audio data using PortAudio (I
I am using C# and Microsoft.Xna.Framework.Audio ; I have managed to record some audio
I'm working on a project on the iPhone where I'm recording audio from the

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.