- 注意:
正确的沙盒路径
#import "ViewController.h"#import@interface ViewController ()
@property(nonatomic,strong) AVAudioRecorder * recoder ;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
//准备文件路径
NSString * path = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:@"123.caf"];
//
// NSString * path = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:@"123.caf"];
//
NSURL * url = [NSURL fileURLWithPath:path];
NSLog(@"%@",url);
self.recoder = [[AVAudioRecorder alloc]initWithURL:url settings:nil error:nil];
[self.recoder prepareToRecord];
}
- (IBAction)start:(id)sender {
[self.recoder record];
}
- (IBAction)pause:(id)sender {
[self.recoder pause];
}
- (IBAction)stop:(id)sender {
[self.recoder stop];
}
@end