应用程序背景时是否可以开始播放音频和静音?

时间:2016-11-28 14:15:18

标签: ios swift swift3 avaudiosession

我创建了一个应用程序,当应用程序背景时开始播放音频。 我从 List<CoreLabel> tokens = sentence.get(TokensAnnotation.class); Tree tree = sentence.get(TreeAnnotation.class); TregexPattern pattern = TregexPattern.compile("NNP | NNS | NN | NNPS"); TregexMatcher matcher = pattern.matcher(tree); HashMap<Tree, Integer> leafDict = new HashMap<>(); int i = 0; for(Tree leaf : tree.getLeaves()) { leafDict.put(leaf, i); i++; } while (matcher.find()) { int index = leafDict.get( matcher.getMatch().firstChild()); String result = tokens.get(index).get(LemmaAnnotation.class); System.out.println(result); } 开始:

AVAudioSession

它工作正常,但是当我的应用开始播放音频时,是否可以将其他应用中的任何其他音频静音?

没有duckOthers选项应用程序崩溃,因为上面的代码是在后台执行的。使用duckOthers,它不会使其他音频静音,只会降低音量。

1 个答案:

答案 0 :(得分:0)

没有。您可以保留其他音频,并且可以中断(暂停,而不是静音)语音(interruptSpokenAudioAndMixWithOthers),但不允许静音所有其他音频。这很明显是出于设计意图,因为静音所有音频通常都是非常糟糕的用户体验,所以即使你找到了一个解决它的技巧,你应该在AppStore评论期间遇到麻烦。 Apple甚至在interruptSpokenAudioAndMixWithOthers文档中提出了他们的意图:

  

当其他音频不是语音时,躲避其他音频,而不是打断它。

相关问题