录音 功能的实现(依然需要导入音频工具框架)
AVAudioSession * session = [[AVAudioSession alloc]init];//创建录音实例
NSError * error = nil;
[session setCategory:@"AVAudioSessionCategoryPlayAndRecord" error:&error];
NSString * string = NSHomeDirectory();// 获取Home路径
NSURL * url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/Documents/recordd.caf",string]];// 创建录音文件
recorder = [[AVAudioRecorder alloc]initWithURL:url settings:@{@"AVSampleRateKey": [NSNumber numberWithFloat:44100.0]} error:&error];//配置录音参数
[recorder prepareToRecord];// 准备录音
[recorder record];// 开始录音
音效播放 <span style="font-family: Arial, Helvetica, sans-serif;">(依然需要导入音频工具框架)</span>
SystemSoundID systemSoundID;
NSURL * url = [[NSBundle mainBundle] URLForAuxiliaryExecutable:@"SystemSound.wav"];//用音效文件创建URL
AudioServicesCreateSystemSoundID((CFURLRef)url, &systemSoundID); //创建音效
AudioServicesPlaySystemSound(systemSoundID);//音效播放