Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Volume Issue with Custom Headset. #5

Open
niki-Solvative opened this issue Sep 19, 2024 · 0 comments
Open

Volume Issue with Custom Headset. #5

niki-Solvative opened this issue Sep 19, 2024 · 0 comments

Comments

@niki-Solvative
Copy link

In our iOS application, we have a custom headset without a microphone. We want users to listen through this headset while speaking via an ipad microphone. However, when we use the default route-changing code in Swift, the iOS system recognizes the iPad as a complete device and routes the audio output through the iPad's speaker instead.

How can we improve this to ensure that audio input is correctly routed to the ipad microphone while allowing audio playback through our custom headset?

Setting the audio session

do {
            let audioSession = AVAudioSession.sharedInstance()
            
            try audioSession.setCategory(AVAudioSession.Category.playAndRecord, options: [.allowBluetoothA2DP])
            try audioSession.setActive(true)
        }catch {
            print("Failed to set up audio session: \(error)")
        }

func configureAudioRouting() {
let audioSession = AVAudioSession.sharedInstance()

do {
    let availableInputs = try audioSession.availableInputs
    if let inputs = availableInputs {
        for input in inputs {
            if input.portType == .bluetoothHFP || input.portType == .headsetMic {
                try audioSession.setPreferredInput(input)
                break
            }
        }
    }
} catch {
    print("Failed to configure audio routing: \(error)")
}

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant