IPhone之AVAudioRecorder
2011-11-07 21:59
281 查看
#import <AVFoundation/AVFoundation.h> 需要引入
第二个参数 settings是一个容纳键值对的NSDictionary有四种一般的键
1:一般的音频设置
2:线性PCM设置
3:编码器设置
4:采样率转换设置
NSMutableDictionary 需要加入五个设置值(线性PCM)
view plain
AVAudioRecorder成功创建后,使用他非常直接.它的三个基本方法如下
view plain
//获取document目录的路径 view plain - (NSString*) documentsPath { if (! _documentsPath) { NSArray *searchPaths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES); _documentsPath = [searchPaths objectAtIndex: 0]; [_documentsPath retain]; } return _documentsPath; } //(document目录的路径) NSString *destinationString = [[self documentsPath] stringByAppendingPathComponent:filenameField.text]; NSURL *destinationURL = [NSURL fileURLWithPath: destinationString]; //初始化AVAudioRecorder NSError *recorderSetupError = nil; AVAudioRecorder audioRecorder = [[AVAudioRecorder alloc] initWithURL:destinationURL settings:recordSettings error:&recorderSetupError]; [recordSettings release];
第二个参数 settings是一个容纳键值对的NSDictionary有四种一般的键
1:一般的音频设置
2:线性PCM设置
3:编码器设置
4:采样率转换设置
NSMutableDictionary 需要加入五个设置值(线性PCM)
view plain
NSMutableDictionary *recordSettings = [[NSMutableDictionary alloc] initWithCapacity:10]; //1 ID号 [recordSettings setObject: [NSNumber numberWithInt: kAudioFormatLinearPCM] forKey: AVFormatIDKey]; float sampleRate = [pcmSettingsViewController.sampleRateField.text floatValue]; //2 采样率 [recordSettings setObject: [NSNumber numberWithFloat:sampleRate] forKey: AVSampleRateKey]; //3 通道的数目 [recordSettings setObject: [NSNumber numberWithInt: (pcmSettingsViewController.stereoSwitch.on ? 2 : 1)] forKey:AVNumberOfChannelsKey]; int bitDepth = [pcmSettingsViewController.sampleDepthField.text intValue]; //4 采样位数 默认 16 [recordSettings setObject: [NSNumber numberWithInt:bitDepth] forKey:AVLinearPCMBitDepthKey]; //5 [recordSettings setObject: [NSNumber numberWithBool: pcmSettingsViewController.bigEndianSwitch.on] forKey:AVLinearPCMIsBigEndianKey]; //6 采样信号是整数还是浮点数 [recordSettings setObject: [NSNumber numberWithBool: pcmSettingsViewController.floatingSamplesSwitch.on] forKey:AVLinearPCMIsFloatKey] ;
AVAudioRecorder成功创建后,使用他非常直接.它的三个基本方法如下
view plain
-(void) startRecording { [audioRecorder record]; } -(void) pauseRecording { [audioRecorder pause]; recordPauseButton.selected = NO; } -(void) stopRecording { [audioRecorder stop]; }
相关文章推荐
- IPhone之AVAudioRecorder
- iphone之AVAudioRecorder
- (iPhone/iPad开发)细数Xcode 4.6+iOS 6 SDK中存在的bug漏洞之MPMoviePlayerController、AVAudioRecorder
- IPhone之AVAudioRecorder
- iphone ios AVAudioRecorder 在调用[AVPlayer play]后无法录音
- IPhone之AVAudioRecorder
- IPhone之AVAudioRecorder
- iPhone开发:使用NSValue存储任意类型的数据
- IPhone开源代码 绝对经典!
- 下一代iPhone前面板设计图曝光 明确采用4英寸屏
- iPhone and iPad JavaScript dialogs (alert, confirm, prompt) and windows
- iphone开发常用代码
- 明天开售的iPhone X为量产降低Face ID技术标准?业内人士说「苹果犯不着」
- IPhone数据库操作代码例子
- 看看成功例子 四款iPhone音乐APP应用赏析
- iphone九宫格的界面
- 创建一个简单的 iOS 5 iPhone App 教程(2/3)
- iPhone开发过程中检测多次Release问题[转]
- 有关iOS11和iPhoneX的适配问题
- Iphone SDK textField 打开和关闭键盘