#import<AVFoundation/AVFoundation.h>
@property(nonatomic,strong)AVAudioRecorder* Recorder;
-(AVAudioRecorder*)Recorder
{
if(!_Recorder) {
NSString* path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES)lastObject];
path = [path stringByAppendingPathComponent:@"dd.acf"];
NSDictionary* settings =@{AVEncoderAudioQualityKey:[NSNumber numberWithInt:AVAudioQualityLow],
AVEncoderBitRateKey:[NSNumbernumberWithInt:16],
AVSampleRateKey:[NSNumbernumberWithFloat:8000],
AVNumberOfChannelsKey:[NSNumbernumberWithInteger:2]
};
_Recorder= [[AVAudioRecorderalloc]initWithURL:[NSURL URLWithString:path]settings:setting serror:nil];
}
return_Recorder;
}
- (IBAction)atart:(id)sender {
NSLog(@"strat");
[self.Recorder record];
}
- (IBAction)stop:(id)sender {
NSLog(@"stop");
[self.Recorder stop];
}
//断音播放
- (IBAction)bofang:(id)sender {
NSString* path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES)lastObject];
path = [path stringByAppendingPathComponent:@"dd.acf"];
SystemSoundID soundID =0;
CFURLRefref = (__bridgeCFURLRef)[NSURL URLWithString:path];
AudioServicesCreateSystemSoundID(ref, &soundID);
AudioServicesPlayAlertSound(soundID);//带震动
AudioServicesPlaySystemSound(soundID);//不带震动
}
网友评论