0

I am currently playing an audio file with "MobileVlcKit" and I need to switch to earSpeaker (top speaker for phone calls) in the middle of playing audio file. Currently I am using this code:

AVAudioSession.sharedInstance().overrideOutputAudioPort(.none)

But it keep playing from main speaker. Do anyone knows what is my problem?

Ali Samaiee
  • 301
  • 6
  • 14

1 Answers1

0

I just checked my 2 years old objective-c code, not sure will it work for you, but worth to try. here is its swift version:

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)
}

Stanislau Baranouski
  • 1,425
  • 1
  • 18
  • 22