在我使用AVAudioRecorder和AVAudioPlayer录制和播放音频的应用程序中,我遇到了来电情况下的场景。在录制过程中,如果来电,音频录制后只能录制电话。我希望录制电话后录制的录音成为录制电话前录制的音频的延续。AVAudioRecorder只录制中断后的音频
我跟踪使用AVAudioRecorderDelegate方法
在录音机中断存在的- (无效)audioRecorderBeginInterruption:(AVAudioRecorder *)avRecorder 和
- (无效)audioRecorderEndInterruption:(AVAudioRecorder *)avRecorder。
在我的EndInterruption方法中,我激活了audioSession。
这里是记录代码,我使用
- (void)startRecordingProcess
{
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
NSError *err = nil;
[audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error:&err];
if(err)
{
DEBUG_LOG(@"audioSession: %@ %d %@", [err domain], [err code], [[err userInfo] description]);
return;
}
[audioSession setActive:YES error:&err];
err = nil;
if(err)
{
DEBUG_LOG(@"audioSession: %@ %d %@", [err domain], [err code], [[err userInfo] description]);
return;
}
// Record settings for recording the audio
recordSetting = [[NSDictionary alloc] initWithObjectsAndKeys:
[NSNumber numberWithInt:kAudioFormatMPEG4AAC],AVFormatIDKey,
[NSNumber numberWithInt:44100],AVSampleRateKey,
[NSNumber numberWithInt: 2],AVNumberOfChannelsKey,
[NSNumber numberWithInt:16],AVLinearPCMBitDepthKey,
[NSNumber numberWithBool:NO],AVLinearPCMIsBigEndianKey,
[NSNumber numberWithBool:NO],AVLinearPCMIsFloatKey,
nil];
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:recorderFilePath];
if (fileExists)
{
BOOL appendingFileExists =
[[NSFileManager defaultManager] fileExistsAtPath:appendingFilePath];
if (appendingFileExists)
{
[[NSFileManager defaultManager]removeItemAtPath:appendingFilePath error:nil];
}
if (appendingFilePath)
{
[appendingFilePath release];
appendingFilePath = nil;
}
appendingFilePath = [[NSString alloc]initWithFormat:@"%@/AppendedAudio.m4a", DOCUMENTS_FOLDER];
fileUrl = [NSURL fileURLWithPath:appendingFilePath];
}
else
{
isFirstTime = YES;
if (recorderFilePath)
{
DEBUG_LOG(@"Testing 2");
[recorderFilePath release];
recorderFilePath = nil;
}
DEBUG_LOG(@"Testing 3");
recorderFilePath = [[NSString alloc]initWithFormat:@"%@/RecordedAudio.m4a", DOCUMENTS_FOLDER];
fileUrl = [NSURL fileURLWithPath:recorderFilePath];
}
err = nil;
recorder = [[recorder initWithURL:fileUrl settings:recordSetting error:&err]retain];
if(!recorder)
{
DEBUG_LOG(@"recorder: %@ %d %@", [err domain], [err code], [[err userInfo] description]);
[[AlertFunctions sharedInstance] showMessageWithTitle:kAppName
message:[err localizedDescription]
delegate:nil
cancelButtonTitle:@"Ok"];
return;
}
//prepare to record
[recorder setDelegate:self];
[recorder prepareToRecord];
recorder.meteringEnabled = YES;
[recorder record];
}
在寻找一个解决这个问题我遇到另一个链接 how to resume recording after interruption occured in iphone?和http://www.iphonedevsdk.com/forum/iphone-sdk-development/31268-avaudiorecorderdelegate-interruption.html其中谈到了同样的问题来了。 我尝试了这些链接中提供的建议,但没有成功。 我希望能够使用AVAudioRecorder本身。 有什么办法可以找到解决这个问题的方法吗? 所有宝贵的建议表示赞赏。
请发帖,你是如何加入这两个文件? –
您可以使用这两个文件适当地创建一个AVComposition。下面的链接有如何做它的示例代码http://stackoverflow.com/questions/7775040/play-avmutablecomposition-with-avplayer。之后,您可以使用AVAssetExportSession将乐曲导出为单个音频文件。通过这个链接http://stackoverflow.com/questions/8019033/avassetexportsession-not-working-in-ios5/9767681#9767681。希望这可以解决你的问题。 – Siddharth