【问题标题】:Core Audio: Working with Speaker, Is it possible to route to the internal speaker- AVAudioSessionPortBuiltInReceiver(Not to loud speaker)核心音频:使用扬声器,是否可以路由到内部扬声器 - AVAudioSessionPortBuiltInReceiver(不是扬声器)
【发布时间】:2016-02-22 05:56:18
【问题描述】:

根据文档,没有关于路由甚至获取“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 class(RouteButton) 可能会列出(路由到) AVAudioSessionPortBuiltInReceiver,是否可以实现相同的目标?

【问题讨论】:

    标签: ios swift core-audio avaudiosession


    【解决方案1】:

    如果您将音频会话配置为播放和录制(并关闭与其他人混合),iPhone 上的默认路由将变为通过较小的耳机播放音频(而不是底部的较大扬声器) ,或者如果用户插入耳机,则将插入的耳机拔出。

    【讨论】:

    • 感谢您的回复。我使用了相同的类别,但仍然通过扬声器播放。
    • 你知道吗,插入耳机后有没有机会获得内置扬声器的端口详细信息。
    【解决方案2】:

    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 调用,你将通过 覆盖 = .speaker

    声音太小了。

    PS 它不适用于 iPad,根据 2017 年 6 月的型号..

    苹果声明:

    https://developer.apple.com/documentation/avfoundation/avaudiosessionportbuiltinreceiver

    AVAudioSessionPortBuiltInReceiver(耳机..)

    输出到打算放在耳朵附近的扬声器。 .. 通常,此扬声器仅适用于 iPhone 设备。

    (颜色用于调试...)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-08-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多