背景音通话后不恢复

背景音通话后不恢复

本文介绍了背景音通话后不恢复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的背景音乐能正常工作,几乎所有的时间。屏幕锁定,或者在静音开关。但是,当用户有在背景中的应用,并且接收到一个呼叫,即使该用户没有应答该呼叫时,背景声频不中断结束后恢复。

My background audio works fine almost all the time. Screen locked, or mute switch on. But when the user has the application in the background, and it receives a call, even if the user doesn't answer the call, the background audio does not resumes after the interruption ends.

音乐应用程序恢复正常背景音乐,如果它被中断。

The Music app properly resumes background audio if it was interrupted.

我缺少某些属性或做我需要有一个回调或者设置一个后台任务,继续中断后的背景音执行?或者,这一点是我们不能做?

Am I missing some property or do I need to have a callback or set a background task to continue background audio execution after an interruption? Or this is something that we can't do?

推荐答案

我们正在呼出电话和呼入呼叫后恢复我们的音频,而应用程序是在后台。

We are resuming our audio after an outbound call and inbound call while the app is in the background.

我们播放音频与AVAudioPlayer并听取他们的AVAudioSessionInterruptionNotification.苹果会自动暂停AVAudioPlayer为大家讲解中断,当你告诉它恢复您收到后中断结束,苹果将重新设置您的会话活跃。请参阅从表3-2 Handling音频中断的建议的,如果你使用的是其他类型的音频技术。

We play audio with AVAudioPlayer and listen to the AVAudioSessionInterruptionNotification. Apple automatically pauses the AVAudioPlayer for you on an interruption and when you tell it to resume after you receive the interruption is over, Apple will set your session active again. See Table 3-2 from Handling Audio Interruptions on recommendations if you are using other types of audio technologies.

订阅通知:

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onAudioSessionEvent:) name:AVAudioSessionInterruptionNotification object:nil];

处理通知:

- (void) onAudioSessionEvent: (NSNotification *) notification
{
    //Check the type of notification, especially if you are sending multiple AVAudioSession events here
    if ([notification.name isEqualToString:AVAudioSessionInterruptionNotification]) {
        NSLog(@"Interruption notification received!");

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

        } else {
            NSLog(@"Interruption ended!");
            //Resume your audio
        }
    }
}

这篇关于背景音通话后不恢复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-26 03:04