【问题标题】:Using AVAudioSession AVAudioSessionCategoryPlayAndRecord mutes all push notifications sounds and vibration. Even with app in background使用 AVAudioSession AVAudioSessionCategoryPlayAndRecord 会静音所有推送通知的声音和振动。即使在后台使用应用程序
【发布时间】:2015-08-06 02:29:24
【问题描述】:

我正在开发一个应用程序,它在应用程序处于前台和后台时都会进行一些记录。哪个正在工作。但是,我注意到每当我的音频会话(见下文)处于活动状态时,“系统”听起来就像推送通知警报声音以及振动静音。即使应用在后台也是如此。

结果是,当我的应用程序处于后台并开启录音时,我停止接收标准内容(如短信)的通知声音/氛围。

音频会话设置如下:

 AVAudioSession* session = [AVAudioSession sharedInstance];
[session setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionMixWithOthers error:&error];

显然,这些声音/振动是不可混合的,所以我猜它们会被静音。

有什么办法可以解决这个问题(同时仍然保持录音有效)?我怎样才能录音并仍然让用户收到推送通知的声音和振动?

【问题讨论】:

  • 嗨@Fraggle,您最终找到解决方案了吗?我自己也在努力解决类似的问题。

标签: ios iphone audio audio-recording avaudiosession


【解决方案1】:

你可以试试这个:

[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord
                                 withOptions:(AVAudioSessionCategoryOptionDefaultToSpeaker | AVAudioSessionCategoryOptionDuckOthers)
                                       error:nil];

此外,您可以尝试使用以下方法停用音频会话:

[[AVAudioSession sharedInstance] setActive:NO withOptions:AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation error:nil];

然后重新激活它:

[[AVAudioSession sharedInstance] setActive:YES error:nil];

【讨论】:

    猜你喜欢
    • 2019-03-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多