录音
2016-02-23 21:50
239 查看
录音
1.#import "ViewController.h" 2.#import "CDMyUtil.h" 3.#import <AVFoundation/AVFoundation.h> 4. 5.@interface ViewController () { 6. AVAudioRecorder *myRecorder; 7. 8. NSDictionary *dict; 9.} 10. 11.@end 12. 13.@implementation ViewController 14. 15.- (void)viewDidLoad { 16. [super viewDidLoad]; 17. 18. // 对AVAudioRecorder对象的设置 19. dict = @{ 20. AVEncoderAudioQualityKey:[NSNumber numberWithInt:AVAudioQualityLow], 21. AVEncoderBitRateKey:[NSNumber numberWithInt:16], 22. AVNumberOfChannelsKey:[NSNumber numberWithInt:2], 23. AVSampleRateKey:[NSNumber numberWithInt:44100] 24. }; 25. 26. NSLog(@"%@", NSHomeDirectory()); 27.} 28. 29.- (IBAction)recordButtonClicked:(UIButton *)sender { 30. if (!myRecorder) { 31. // 指定一个文件路径 32. NSString *filePath = [NSHomeDirectory() stringByAppendingString:[NSString stringWithFormat:@"/Documents/%@.caf", [CDMyUtil timeStringWithFormat:@"yyyyMMddHHmmssSSS"]]]; 33. // 通过文件路径获得文件的URL 34. NSURL *fileUrl = [NSURL fileURLWithPath:filePath]; 35. // 创建AVAudioRecorder对象 36. myRecorder = [[AVAudioRecorder alloc] initWithURL:fileUrl settings:dict error:nil]; 37. } 38. 39. 40. if (myRecorder.isRecording) { 41. [myRecorder stop]; // 结束录制 42. [sender setTitle:@"录音" forState:UIControlStateNormal]; 43. myRecorder = nil; 44. } 45. else { 46. [myRecorder prepareToRecord]; 47. [myRecorder record]; // 开始录制 48. [sender setTitle:@"结束" forState:UIControlStateNormal]; 49. } 50.} 51. 52.@end 53.
相关文章推荐
- S - stl 的mapⅠ
- linker command failed with exit code 1 (use -v to see invocation)
- Android日常开发60条经验
- 瑞芯微RK3188如何配置USB摄像头支持
- 瑞芯微RK3188如何配置USB摄像头支持
- C++2远征之离港篇
- java设计模式之策略模式
- 瑞芯微RK3188如何配置USB摄像头支持
- JDK5并发(2) Locks-ReentrantLock
- MySQL索引
- jQuery--基础知识速查表
- localhost与127.0.0.1的区别
- kidd风IOS开发日志之Git的常用终端指令
- 对于恶意诈骗短信中包含的链接的一次研究
- yii phpexcel自己主动生成文件保存到server上
- 百度金矿 百度矿机内测 迅雷赚钱宝 Pro QQ群 289013426
- 两种ModelAndView接的参数视图路径之间的区别
- MapReduce调试,通过计数器输出变量值到控制台显示
- C——1
- K&R练习题6-1统计关键词出现的次数