核心音频:使用扬声器,是否可以路由到内置扬声器-AVAudioSessionPortBuiltInReceiver(不要扬声器)
根据文档,Ther没有关于路由甚至获取“AVAudioSessionPortBuiltInReceiver”的端口详细信息的文档。 (注意:请再读一遍,它不是关于这个端口AVAudioSessionPortBuiltInSpeaker
) 。
正如我发现的那样,只有可能的overrideOutputAudioPort
才能完成
public enum AVAudioSessionPortOverride : UInt { case None case Speaker }
问题是,是否有可能通过以下方式播放音频:
public let AVAudioSessionPortBuiltInReceiver: String /* The speaker you hold to your ear when on a phone call */
编辑:使用MPVolumeView
类(RouteButton)列出(路由到)AVAudioSessionPortBuiltInReceiver可能,是否有可能实现相同?
如果您将音频会话配置为播放和录音(并且与其他人保持混音),则iPhone上的默认路线将变为播放较小的耳机(而不是底部较大的扬声器)的音频,或者输出插入式耳机,如果用户插入耳机。
Apple将它们称为“接收器”(即顶级耳机)和扬声器。
在这两者之间切换:
final private func changed(overrideNone: Bool) { let audioSession = AVAudioSession.sharedInstance() var override : AVAudioSessionPortOverride = .none if overrideNone{ color = UIColor.red override = .none } else{ color = UIColor.yellow override = .speaker } self.view.backgroundColor = color do { try audioSession.overrideOutputAudioPort(override) } catch _ { } }
如果您使用false调用,则将通过override = .speaker播放
这么低的扬声器。
PS它不适用于iPad,如2017年6月的型号..
Apple说:
https://developer.apple.com/documentation/avfoundation/avaudiosessionportbuiltinreceiver
AVAudioSessionPortBuiltInReceiver(听筒……)
输出到要靠近耳朵的扬声器。 ..通常,此扬声器仅适用于iPhone设备。
(颜色用于调试……)