美文网首页
录音,短音播放

录音,短音播放

作者: 40dd4b561abe | 来源:发表于2017-06-13 10:22 被阅读13次
#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);//不带震动

}

相关文章

网友评论

      本文标题:录音,短音播放

      本文链接:https://www.haomeiwen.com/subject/ducdqxtx.html