IPhone之AVAudioRecorder
来源:互联网 发布:php接口安全 编辑:程序博客网 时间:2024/06/09 14:47
#import <AVFoundation/AVFoundation.h> 需要引入
//获取document目录的路径
[cpp] view plaincopy
- - (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)
[java] view plaincopy
- 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成功创建后,使用他非常直接.它的三个基本方法如下
[java] view plaincopy
- -(void) startRecording {
- [audioRecorder record];
- }
- -(void) pauseRecording {
- [audioRecorder pause];
- recordPauseButton.selected = NO;
- }
- -(void) stopRecording {
- [audioRecorder stop];
- }
- IPhone之AVAudioRecorder
- IPhone之AVAudioRecorder
- IPhone之AVAudioRecorder
- iphone之AVAudioRecorder
- IPhone之AVAudioRecorder 录音
- IPhone之AVAudioRecorder AVplayer
- 详解IPhone之 AVAudioRecorder 代码实现
- 音频录制之AVAudioRecorder
- 音频录制之AVAudioRecorder
- 音频录制之AVAudioRecorder
- IOS开发之AVAudioRecorder
- AVAudioRecorder
- (iPhone/iPad开发)细数Xcode 4.6+iOS 6 SDK中存在的bug漏洞之MPMoviePlayerController、AVAudioRecorder
- iphone ios AVAudioRecorder 在调用[AVPlayer play]后无法录音
- iphone ios AVAudioRecorder 录音后用avplayer播放声音小
- iOS 之录音笔,AVAudioRecorder,AVAudioPlayer的使用
- AVAudioRecorder 录制
- AVAudioRecorder 录音
- iPhone 开发过程中的一些小技术的总结
- 总结个人经验,史上最完整的IDP申请直到软件上架销售流程
- 申请IDP图文教程
- 杂感
- 中括号和大括号在正则表达式的转义,包括很多特殊字符
- IPhone之AVAudioRecorder
- 使用github管理iOS分布式项目开发
- iOS开发心得分享
- Web Services--gSOAP 2.7.6 第一章(1.1)
- Ubuntu安装tftp服务器
- iOS中plist的读写操作
- 解读iPhone平台的一些优秀设计思路
- 黑马程序员_java_IO
- Objective-C与JavaScript的交互