#import <AVFoundation/AVFoundation.h>
{
Nsinteger _timecount;
Nstimer *_timer;
}
@property (Nonatomic,retain) Avaudioplayer *audioplayer;
@property (Nonatomic,retain) Avaudiorecorder *recorder;
@property (nonatomic,assign) Nsinteger Playtag;
/**
* Create Sound Recorder
*/
-(Avaudiorecorder *) recorder{
if (!_recorder) {
Nsurl *url = [self filePath];
Nsdictionary *setting = [nsdictionary dictionarywithobjectsandkeys:[nsnumber numberwithint:avaudioqualitymin], Avencoderaudioqualitykey,[nsnumber Numberwithint:16],avencoderbitratekey,[nsnumber NumberWithInt:2], Avnumberofchannelskey,[nsnumber Numberwithfloat:44100.0],avsampleratekey,nil];
Nserror *error=nil;
_recorder=[[avaudiorecorder Alloc]initwithurl:url settings:setting error:&error];
_recorder.delegate=self;
_recorder.meteringenabled=yes;
if (Error) {
NSLog (@ "Recording error:%@", error.localizeddescription);
}
[_recorder Preparetorecord];
}
return _recorder;
}
Returns the path of the file
-(Nsurl *) FilePath
{
NSString *strpath=[nstemporarydirectory () stringbyappendingpathcomponent:@ "AAA.CAF"];
NSLog (@ "%@-----------", strpath);
Nsurl *url=[nsurl Fileurlwithpath:strpath];
return URL;
}
Pop-up recording page
-(void) addaudioview{
self.navigationItem.rightBarButtonItem.enabled = NO;
_backview = [[UIView alloc]initwithframe:cgrectmake (0, 0, WIDTH, HEIGHT)];
_backview.alpha = 0.5;
_backview.backgroundcolor = [Uicolor blackcolor];
[Self.view Addsubview:_backview];
_audioview = (Audiorecorderalterview *) [[[NSBundle mainbundle]loadnibnamed:@ "Audiorecorderalterview" Owner:nil Options:nil]lastobject];
_audioview.frame = CGRectMake (0, 64, 200, 200);
_audioview.center = Cgpointmake (self.view.center.x, 200);
[_audioview.endbtn addtarget:self Action: @selector (Pulishvedio) forcontrolevents:uicontroleventtouchupinside];
[_audioview.cannelbtn addtarget:self Action: @selector (Canclebtnclick) forControlEvents: UIControlEventTouchUpInside];
[Self.view Addsubview:_audioview];
}
Click the Record button
-(Ibaction) Vediobtnclick: (ID) Sender {
if ([_audioplayer isplaying]) {
[_audioplayer stop];
Uiimageview *animationimageview_last = (Uiimageview *) [Self.view Viewwithtag:_playtag + 10000];
[Animationimageview_last stopanimating];
}
if ([self Canrecord]) {
[Self addaudioview];
if (![ Self.recorder IsRecording]) {
[Self.recorder Record];
}
[Self addtimer];
}
}
iOS recording, audio playback function