当应用程序背景时,我制作了一个开始播放音频的应用程序.
我通过以下方式启动AVAudioSession:
我通过以下方式启动AVAudioSession:
do { try audioSession.setCategory(AVAudioSessionCategoryPlayback,with: .duckOthers) } catch { }
它工作正常,但是当我的应用程序开始播放音频时,是否可以将其他应用程序中的任何其他音频静音?
没有duckOthers选项应用程序崩溃,因为上面的代码是在后台执行的.使用duckOthers,它不会使其他音频静音,只会降低音量.
解决方法
不可以.您可以保留其他音频,并且可以中断(暂停,而不是静音)语音(interruptSpokenAudioAndMixWithOthers),但不允许静音所有其他音频.这很明显是出于设计意图,因为静音所有音频通常都是非常糟糕的用户体验,所以即使你找到了一个解决它的技巧,你应该在AppStore评论期间遇到麻烦. Apple甚至在interruptSpokenAudioAndMixWithOthers文档中调出了他们的意图:
Ducking other audio,rather than interrupting it,is appropriate when the other audio is not spoken audio.