如何在iOS中以编程方式切换到earSpeaker?

问题描述 投票:0回答:1

我目前正在播放带有“MobileVlcKit”的音频文件,我需要在播放音频文件的过程中切换到earSpeaker(用于通话的顶级扬声器)。目前我正在使用此代码:

AVAudioSession.sharedInstance().overrideOutputAudioPort(.none)

但它继续从主要演讲者播放。有谁知道我的问题是什么?

ios swift avfoundation vlc avaudiosession
1个回答
0
投票

我刚刚检查了我2岁的Objective-c代码,不确定它是否适合您,但值得尝试。这是它的快速版本:

let audioSession = AVAudioSession.sharedInstance()
do {
    try audioSession.setActive(false)
    try audioSession.setCategory(.playAndRecord, options: .defaultToSpeaker)
    try audioSession.overrideOutputAudioPort(.none)
    try audioSession.setActive(true)
} catch {
    // handle error
    print(error)
}

© www.soinside.com 2019 - 2024. All rights reserved.