- Home /
Question by
SajjadZare · Oct 24, 2010 at 06:26 AM ·
iphonexcode
Problem in record sound
I use below code for record sound but this code record every sound that play around device How can i change it that just record sound that play with AVAudioPlayer in the app?
-(void)start { NSError *err = nil; AVAudioSession *audioSession = [AVAudioSession sharedInstance]; [audioSession setCategory :AVAudioSessionCategoryPlayAndRecord error:&err]; [audioSession setActive:YES error:&err];
recordSetting = [[NSMutableDictionary alloc] init];
[recordSetting setValue :[NSNumber numberWithInt:1768775988] forKey:AVFormatIDKey];
[recordSetting setValue:[NSNumber numberWithFloat:96000] 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];
NSDate *now = [NSDate dateWithTimeIntervalSinceNow:0];
NSString *name = [now description];
recorderFilePath = [[NSString stringWithFormat:@"%@/%@.caf", DOCUMENTS_FOLDER, name] retain];
NSURL *url = [NSURL fileURLWithPath:recorderFilePath];
recorder = [[ AVAudioRecorder alloc] initWithURL:url settings:recordSetting error:&err];
[recorder setDelegate:self];
[recorder prepareToRecord];
recorder.meteringEnabled = YES;
[recorder record];
}//start
Comment