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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T11:31:41+00:00 2026-06-05T11:31:41+00:00

I have 2 classes, a record and a player. In my main scene, I

  • 0

I have 2 classes, a record and a player. In my main scene, I create an instance of them and play and record. But, as I see, it only records and somehow does not play (the file is not there!)

Here is the code for both :

-(void)record {
    NSArray *dirPaths;
    NSString *docsDir;
    NSString *sound= @"sound0.caf" ;
    dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) ;
    docsDir = [dirPaths objectAtIndex:0];
    NSString *soundFilePath = [docsDir stringByAppendingPathComponent:sound];
    NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath];

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

    NSError *error;
    myRecorder = [[AVAudioRecorder alloc] initWithURL:soundFileURL settings:settings error:&error];

    if (myRecorder)  {
        NSLog(@"rec");
        [myRecorder prepareToRecord];
        myRecorder.meteringEnabled = YES;
        [myRecorder record];
    } else
        NSLog( @"error"  );
}

I can see the log of rec.

-(void)play {
  NSArray *dirPaths;
  NSString *docsDir;
  dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
    NSUserDomainMask, YES);
  docsDir = [dirPaths objectAtIndex:0];
  NSString *soundFilePath1 =  @"sound0.caf" ;
  NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath1];
  BOOL isMyFileThere = [[NSFileManager defaultManager] fileExistsAtPath:soundFilePath1];
  if(isMyFileThere) {
    NSLog(@"PLAY"); 
    avPlayer1 = [[AVAudioPlayer alloc] initWithContentsOfURL:soundFileURL error:NULL];
    avPlayer1.volume = 8.0;
    avPlayer1.delegate = self;
    [avPlayer1 play];
 }
}

I DONT SEE THE LOG OF PLAY !

I call them both with:

recInst=[recorder alloc]; //to rec
[recInst record];

plyInst=[player alloc]; //play
[plyInst play];

and to stop the recorder:

- (void)stopRecorder {
    NSLog(@"stopRecordings");
    [myRecorder stop];
    //[myRecorder release];    
}

What’s wrong here? Thanks.

  • 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-05T11:31:43+00:00Added an answer on June 5, 2026 at 11:31 am

    In your record method, you’re appending the file name to the path with:

    NSString *soundFilePath = [docsDir stringByAppendingPathComponent:@"sound0.caf"];
    

    You do not do that in your play method, so it’s looking for the file in whatever the current working directory is, rather than the Documents directory.

    You need to do:

    NSString *soundFilePath1 = [docsDir stringByAppendingPathComponent:@"sound0.caf"];
    

    instead of:

    NSString *soundFilePath1 =  @"sound0.caf" ;
    

    And just another note: soundFilePath and soundFilePath1 are both local variables. Therefore, they are not visible outside their respective methods. Thus, it’s not necessary to give them different names. You can call them both soundFilePath and there will not be a conflict.

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

Sidebar

Related Questions

I have classes which have automatic properties only like public customerName {get; set;}. They
Right now I have classes like: abstract class Record { // Required fields val
I'm using Active Record outside of rails and I have two AR classes similar
I have those classes, an implementation of active record pattern: public abstract class RecordCollection<T>
I have two rails active record classes, School and Instructor linked by a has_and_belongs_to_many
I have an array of classes with a property Date , i.e.: class Record
I have a set of linq to sql classes and serialized them into JSON
I have some issues in Rails Active Record Inheritance, I need to create a
suppose we have these classes: public class Record { int key; int value; Record(){
I have classes that are named exactly the same across different plug-ins that I

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.