繁体   English   中英

来电后继续录音?

[英]Resume audio recording after incoming call?

我们正在使用AVAudioRecorder录制音频,但是无论何时收到任何来电,录音都会停止。 如果我们尝试再次继续录制,则它将从头开始。 我已经检查了语音备忘(iOS苹果应用程序)并发现了相同的问题。 我还检查了音频队列服务示例代码(SpeakHere),但同样存在问题。 因此,请帮助在来电后如何恢复录音?

注意:-我知道有很多与录音有关的问题,但无法找到解决方案。所以请帮助,我们非常感谢您的帮助。 提前致谢。

在iOS中,可以在传入呼叫后恢复音频录制。这的基本概念是使用AVAudioSessionAudioQueue ,当您在设备上收到传入呼叫时,它将给出kAudioSessionBeginInterruption,并且在断开呼叫时您会得到一个kAudioSessionEndInterruption ............接听来电后,只需暂停音频队列,然后[AVAVSessionSessionInstance] setActive:NO er​​ror:nil]; ......然后在kAudioSessionEndInterruption上 ,当呼叫结束时,只需恢复已暂停的队列,然后[[AVAudioSession sharedInstance] setActive:YES error:nil];

这将起作用......我已经成功运行了程序,并在接到来电后能够继续录音......

希望这个能对您有所帮助.......

苹果将AVAudioSessionInterruption观察器解释为一种处理中断的新方法。 Apple在页的Swift中对其进行了解释,但对于那些搜索Objective-C代码的人来说,这个github问题必须是有用的。

您需要处理音频中断,例如

AVAudioSession *session = [AVAudioSession sharedInstance];
[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(audioSessionInterruptionNotification:)
                                             name:AVAudioSessionInterruptionNotification
                                           object:session];

您的音频会话中断通知在其中AVAudioSessionInterruptionNotification类似于

-(void)audioSessionInterruptionNotification:(NSNotification*)notification {

NSString* seccReason = @"";

//Check the type of notification, especially if you are sending multiple AVAudioSession events here
NSLog(@"Interruption notification name %@", notification.name);

if ([notification.name isEqualToString:AVAudioSessionInterruptionNotification]) {
    seccReason = @"Interruption notification received";

    //Check to see if it was a Begin interruption
    if ([[notification.userInfo valueForKey:AVAudioSessionInterruptionTypeKey] isEqualToNumber:[NSNumber numberWithInt:AVAudioSessionInterruptionTypeBegan]]) {
        seccReason = @"Interruption began";

    } else if([[notification.userInfo valueForKey:AVAudioSessionInterruptionTypeKey] isEqualToNumber:[NSNumber numberWithInt:AVAudioSessionInterruptionTypeEnded]]){
        seccReason = @"Interruption ended!";
        //Resume your audio
    }
}
}

您需要编写处理代码,然后才能开始和结束中断。

使用AVFoundation委托方法,

-(void)audioRecorderBeginInterruption:(AVAudioRecorder *)recorder
{
    [audiorecorder pause];
}
-(void)audioRecorderEndInterruption:(AVAudioRecorder *)recorder
{
    [audiorecorder record];
} 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM