iphone – iOS中的电话中断后AUGraph停止运行

iphone – iOS中的电话中断后AUGraph停止运行,第1张

概述我正在使用AUGraph和AUSampler将MIDI信号转换为音频.该应用程序运行正常,但如果应用程序被中断,即通过电话或计时器,则会出现问题.中断后,AUGraph停止运行,没有任何声音.再次获得声音的唯一方法是重新启动应用程序.我正在使用标准方法来处理中断: [[NSNotificationCenter defaultCenter] addObserver: self 我正在使用AUGraph和AUSampler将MIDI信号转换为音频.该应用程序运行正常,但如果应用程序被中断,即通过电话或计时器,则会出现问题.中断后,AUGraph停止运行,没有任何声音.再次获得声音的唯一方法是重新启动应用程序.我正在使用标准方法来处理中断:

[[NSNotificationCenter defaultCenter] addobserver: self                                         selector: @selector(handleInterruption:)                                             name: AVAudioSessionInterruptionNotification                                           object: [AVAudioSession sharedInstance]];

当中断时,调用handleInterruption方法:

// If the system interrupts the audio session - kill the volume-(voID) handleInterruption: (NSNotification *) notification {    NSDictionary *interuptionDict = notification.userInfo;    NSInteger interuptionType = [[interuptionDict valueForKey:AVAudioSessionInterruptionTypeKey] intValue];    if (interuptionType == AVAudioSessionInterruptionTypeBegan) {        [self setAudioSessionActive: NO];        [self stopAUGraph];    }    else if (interuptionType == AVAudioSessionInterruptionTypeEnded) {        [self setAudioSessionActive: YES];        [self startAUGraph];    }}

以下是启动和停止AUGraph的方法

-(voID) startAUGraph {    Checkerror(AUGraphStart(_audioGraph),"Failed to start Audio Graph");}-(voID) stopAUGraph {    Boolean isRunning = false;    // Check to see if the graph is running.    Checkerror(AUGraphIsRunning(_audioGraph,&isRunning),"Error trying querying whether graph is running");    // If the graph is running,stop it.    if (isRunning) {        Checkerror(AUGraphStop(_audioGraph),"Failed to stop Audio Graph");    }}

这是setAudioSessionActive方法:

-(voID) setAudioSessionActive: (BOol) active {    NSError *audioSessionError = nil;    BOol success = [_audioSession setActive:active error:&audioSessionError];    if (!success) {        NSLog (@"Error activating audio session!");    }}

我在渲染回调中设置了一个断点,所以我可以确认AUGraph没有运行.以前有没有人遇到过这个问题?为了让AUGraph再次运行,我还有别的办法吗?提前致谢!

解决方法 我也遇到过这个BUG的可怕麻烦.我想我找到了一个解决方法:

由于在呼叫中断后返回时NSNotifications不会触发,因此在我的AppDelegate的-applicationWillEnterForeground:方法中,我检查是否存在导致其进入后台的中断(当AVAudioSessionInterruptionNotification与AVAudioSessionInterruptionTypeBegan一起发布时,我设置了一个标志作为中断类型键)如果是这样,我在控制运行以下内容的AUGraph的对象中调用一个方法:

Boolean isRun = FALSE;    AUGraphIsRunning(myAUGraph,&isRun);    if (isRun) {        NSLog(@"END INTERRUPTION BUT AUGRAPH IS RUNNING");        AUGraphStop(myAUGraph);// Kick start the AUGraph!        AUGraphStart(myAUGraph); //Restart immediately        Boolean isInit = FALSE;        AUGraphIsInitialized(processingGraph,&isInit);        if (!isInit) {            NSLog(@"augraph not initd'");            Osstatus result = AUGraphInitialize(processingGraph);            if (result != noErr) {                NSLog(@">>can't init graph");            }        }    }    else    {        NSLog(@"END INTERRUPTION BUT AUGRAPH IS NOT RUNNING");    }

关键似乎是停止,然后立即重新启动AUGraph.到目前为止,当呼叫进入或其他应用程序接管扬声器/麦克风时,它可以正常运行我可以在我的应用程序停止的地方接听.

AUGraph的重新初始化似乎永远不会执行,也不是运行,但是我还是把它留下来了.希望这有助于你的情况,我花了几天时间来破解这个,我希望它继续工作而不仅仅是巧合! 4个小时,到目前为止计数!

总结

以上是内存溢出为你收集整理的iphone – iOS中的电话中断后AUGraph停止运行全部内容,希望文章能够帮你解决iphone – iOS中的电话中断后AUGraph停止运行所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/1079980.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-27
下一篇2022-05-27

发表评论

登录后才能评论

评论列表(0条)

    保存