录音与播放

2016-07-06  本文已影响30人  温暖的弦Y

介绍:https://github.com/pattyXP

引用头文件 #import"Mp3Recorder.h" 录制音频,需要设置delegate

#import"UUAVAudioPlayer.h" 播放音频



- (void)initData

{

self.mp3Recorder= [[Mp3Recorderalloc]initWithDelegate:self];

}

//开始录音

- (void)click1

{

[self.mp3RecorderstartRecord];

self.playTime=0;

self.playTimer= [NSTimerscheduledTimerWithTimeInterval:1target:selfselector:@selector(countVoiceTime)userInfo:nilrepeats:YES];

}

//开始播放

- (void)click2

{

}

//录音时间

- (void)countVoiceTime

{

self.playTime++;

if(self.playTime>5) {

[selfendRecordVoice];

}

}

//结束录音

- (void)endRecordVoice

{

if(self.playTimer) {

[self.mp3RecorderstopRecord];

[self.playTimerinvalidate];

self.playTimer=nil;

}

}

#pragma mark -录音回调

- (void)endConvertWithData:(NSData*)voiceData

{

self.audioPlayer= [UUAVAudioPlayersharedInstance];

//self.audioPlayer.delegate = self;

[self.audioPlayerplaySongWithData:voiceData];

}

- (void)viewDidLoad {

[superviewDidLoad];

[selfinitData];

//录音

UIButton*btn = [[UIButtonalloc]initWithFrame:CGRectMake(100,100,80,80)];

btn.backgroundColor= [UIColorredColor];

[self.viewaddSubview:btn];

[btnaddTarget:selfaction:@selector(click1)forControlEvents:UIControlEventTouchUpInside];

//播放

UIButton*btn2 = [[UIButtonalloc]initWithFrame:CGRectMake(100,300,80,80)];

btn2.backgroundColor= [UIColorgreenColor];

[self.viewaddSubview:btn2];

[btn2addTarget:selfaction:@selector(click2)forControlEvents:UIControlEventTouchUpInside];

// Do any additional setup after loading the view, typically from a nib.

}

上一篇 下一篇

猜你喜欢

热点阅读