Iphone 目标C:在特定时间录制后自动播放
你好,你能帮我制作一个录音项目吗?在你用AVAudioRecorder录音后,它会在一定时间内自动播放。你能给我或给我一个关于我的问题的链接吗?我非常需要你的帮助,因为我是iOS开发的新手。提前谢谢各位。祝你今天愉快 这是我的代码@startrecording:Iphone 目标C:在特定时间录制后自动播放,iphone,objective-c,ios,avfoundation,openal,Iphone,Objective C,Ios,Avfoundation,Openal,你好,你能帮我制作一个录音项目吗?在你用AVAudioRecorder录音后,它会在一定时间内自动播放。你能给我或给我一个关于我的问题的链接吗?我非常需要你的帮助,因为我是iOS开发的新手。提前谢谢各位。祝你今天愉快 这是我的代码@startrecording: -(void)startRecording:(UIButton *)sender { //for recording recStopBtn.enabled=NO; recStopBtn.hidden = NO;
-(void)startRecording:(UIButton *)sender
{ //for recording
recStopBtn.enabled=NO;
recStopBtn.hidden = NO;
recStopBtn.enabled =YES;
playRecBtn.enabled = NO;
loading.hidden = NO;
[loading startAnimating];
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
NSError *err = nil;
[audioSession setCategory :AVAudioSessionCategoryPlayAndRecord error:&err];
if(err)
{
NSLog(@"audioSession: %@ %d %@", [err domain], [err code], [[err userInfo] description]);
return;
}
[audioSession setActive:YES error:&err];
err = nil;
if(err)
{
NSLog(@"audioSession: %@ %d %@", [err domain], [err code], [[err userInfo] description]);
return;
}
recordSetting = [[NSMutableDictionary alloc] init];
// We can use kAudioFormatAppleIMA4 (4:1 compression) or kAudioFormatLinearPCM for nocompression
[recordSetting setValue :[NSNumber numberWithInt:kAudioFormatAppleIMA4] forKey:AVFormatIDKey];
// We can use 44100, 32000, 24000, 16000 or 12000 depending on sound quality
[recordSetting setValue:[NSNumber numberWithFloat:16000.0] forKey:AVSampleRateKey];
// We can use 2(if using additional h/w) or 1 (iPhone only has one microphone)
[recordSetting setValue:[NSNumber numberWithInt: 1] forKey:AVNumberOfChannelsKey];
// These settings are used if we are using kAudioFormatLinearPCM format
//[recordSetting setValue :[NSNumber numberWithInt:16] forKey:AVLinearPCMBitDepthKey];
//[recordSetting setValue :[NSNumber numberWithBool:NO] forKey:AVLinearPCMIsBigEndianKey];
//[recordSetting setValue :[NSNumber numberWithBool:NO] forKey:AVLinearPCMIsFloatKey];
recorderFilePath = [NSString stringWithFormat:@"%@/MySound.caf", DOCUMENTS_FOLDER];
NSLog(@"recorderFilePath: %@",recorderFilePath);
NSURL *url = [NSURL fileURLWithPath:recorderFilePath];
err = nil;
NSData *audioData = [NSData dataWithContentsOfFile:[url path] options: 0 error:&err];
if(audioData)
{
NSFileManager *fm = [NSFileManager defaultManager];
[fm removeItemAtPath:[url path] error:&err];
}
err = nil;
recorder = [[ AVAudioRecorder alloc] initWithURL:url settings:recordSetting error:&err];
if(!recorder){
NSLog(@"recorder: %@ %d %@", [err domain], [err code], [[err userInfo] description]);
UIAlertView *alert =
[[UIAlertView alloc] initWithTitle: @"Warning"
message: [err localizedDescription]
delegate: nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
return;
}
//prepare to record
[recorder setDelegate:self];
[recorder prepareToRecord];
recorder.meteringEnabled = YES;
BOOL audioHWAvailable = audioSession.inputIsAvailable;
if (! audioHWAvailable) {
UIAlertView *cantRecordAlert =
[[UIAlertView alloc] initWithTitle: @"Warning"
message: @"Audio input hardware not available"
delegate: nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[cantRecordAlert show];
return;
}
// start recording
[recorder record];
lblStatusMsg.text = @"Recording...";
NSLog(@"RECORDING");
//recIcon.image = [UIImage imageNamed:@"rec_icon.png"];
//progressView.progress = 0.0;
//timer = [NSTimer scheduledTimerWithTimeInterval:6.0 target:self selector:@selector(handleTimer) userInfo:nil repeats:YES];
}
如果您所需要的只是如何在一定时间后使事情发生,请使用
NSTimer
。我看到您的代码中已经注释掉了一个
要记录一定时间,请使用recordForDuration
。要手动停止录制,请使用stop
。要播放录音,请使用AVAudioPlayer
方法initWithContentsOfURL
中AVAudioRecorder
的url
属性
因此,基本上,取消注释您的NSTimer
,然后执行以下操作
AVAudioPlayer *player;
- (void) handleTimer
{
player = [[AVAudioPlayer alloc] initWithContentsOfURL:nameOfAudioRecorder.url];
}
这个问题主要要求为您编写代码。太宽了。请阅读常见问题解答,重新编写,然后返回给我们。@EricBrotto-很抱歉,先生。。我发布了我的代码。。。这是…如果你需要帮助,试着告诉我们你的代码现在做什么,以及你想让它做什么。如果您已经做了一些工作,并且只需要一些提示或疑难解答,您将得到最大的帮助。@Dustin我在这里发布的代码。。是为了我的开始记录行动。。。我想知道它是如何在特定时间后自动播放的。。