0

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

AVAudioSession.sharedInstance().overrideOutputAudioPort(.none)

但它一直从主扬声器播放。有谁知道我的问题是什么?

4

1 回答 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)
}

于 2019-04-28T10:49:46.120 回答