Core Audio: Working with Speaker, Is it possible to route to the internal speaker- AVAudioSessionPortBuiltInReceiver(Not to loud speaker)

我的梦境 提交于 2019-12-23 17:27:55

问题


As per the docs, Ther is no documentation about routing or even getting of the Port details for the "AVAudioSessionPortBuiltInReceiver". (Note: Please read again, its not about this port AVAudioSessionPortBuiltInSpeaker) .

As I found that and only possible overrideOutputAudioPort can be done only for

    public enum AVAudioSessionPortOverride : UInt {
    case None
    case Speaker
    }

The Question is, Is ther any possibilities to play an audio through the :

public let AVAudioSessionPortBuiltInReceiver: String /* The speaker you hold to your ear when on a phone call */

Edit: Using MPVolumeView class(RouteButton) is listing out(routing to) of the AVAudioSessionPortBuiltInReceiver possible, Is it possible to achieve the same?.


回答1:


If you configure the audio session for play-and-record (and leave mix-with-others off), the default route on an iPhone becomes to play audio out the smaller ear speaker (not the louder speaker on the bottom), or out the plugged-in headset, if the user plugs a headset in.




回答2:


Apple calls them "receiver" (i.e. top earpiece) and speaker.

to toggle between these two:

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 _ {

            }   
        }

If You call with false, You will play via override = .speaker

so lower speaker.

PS it does NOT work with iPads, as per june 2017 models..

Apple states:

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

AVAudioSessionPortBuiltInReceiver (earpiece..)

Output to a speaker intended to be held near the ear. .. Typically, this speaker is available only on iPhone devices.

(colors are for debug...)



来源:https://stackoverflow.com/questions/35546668/core-audio-working-with-speaker-is-it-possible-to-route-to-the-internal-speake

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!