Я пытаюсь воспроизвести звук нажатия кнопки, когда начинаю запись звука. Можно ли воспроизводить звук, пока он записывается, вживую?Как воспроизводить звук нажатия кнопки при записи звука?
Требования:
1) если я нажать на кнопку записи, не хотят, чтобы начать запись после завершения Кнопка записи водопроводную sound.it занимает время задержки.
2) Если я нажимаю на кнопку записи, не хочу записывать звук говядины в записанный аудиофайл.
3) Я хочу, чтобы звук нажатия кнопки воспроизведения и запись звука одновременно не перекрывались.
начала записи:
-(IBAction)btnRecordTap:(id)sender
{
[self playTapSound:@"press.wav"];
// Set the audio file
NSArray *pathComponents = [NSArray arrayWithObjects:
[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject],
@"MyAudioMemo.m4a",
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:44100.0] forKey:AVSampleRateKey];
[recordSetting setValue:[NSNumber numberWithInt: 2] forKey:AVNumberOfChannelsKey];
// Initiate and prepare the recorder
recorder = [[AVAudioRecorder alloc] initWithURL:outputFileURL settings:recordSetting error:NULL];
recorder.delegate = self;
recorder.meteringEnabled = YES;
[recorder prepareToRecord];
}
игры Система звука
//---------------play button sound--------------------
-(SystemSoundID) playASound: (NSString *) fileName
{
//Get the filename of the sound file:
NSString *path = [NSString stringWithFormat:@"%@/%@",
[[NSBundle mainBundle] resourcePath],
fileName];
//Get a URL for the sound file
NSURL *filePath = [NSURL fileURLWithPath:path isDirectory:NO];
AudioServicesCreateSystemSoundID((__bridge CFURLRef)filePath, &soundFileObject);
//play the file
AudioServicesPlaySystemSound(soundFileObject);
return soundFileObject;
}
-(void)playTapSound:(NSString *)file
{
SystemSoundID id = [self playASound:file];
AudioServicesAddSystemSoundCompletion (id,NULL,NULL,completionCallback,(__bridge_retained void *)self);
}
static void completionCallback (SystemSoundID ssID,void *clientData)
{
AudioServicesRemoveSystemSoundCompletion (ssID);
AudioServicesDisposeSystemSoundID(ssID);
}