I am constructing an app that may enable customers to report voice notes. The performance of all that’s working nice; I am attempting to now implement adjustments to the AudioSession to handle attainable audio streams from different apps. I would like it in order that if there may be audio enjoying from a special app, and the consumer opens my app; the audio hold enjoying. After we begin recording, any third social gathering app audio ought to cease, and may then can resume once more once we cease recording.
That is my most important audio setup code:
non-public var audioEngine: AVAudioEngine!
non-public var inputNode: AVAudioInputNode!
func setupAudioEngine() {
audioEngine = AVAudioEngine()
inputNode = audioEngine.inputNode
audioPlayerNode = AVAudioPlayerNode()
audioEngine.connect(audioPlayerNode)
let format = AVAudioFormat(standardFormatWithSampleRate: AUDIO_SESSION_SAMPLE_RATE, channels: 1)
audioEngine.join(audioPlayerNode, to: audioEngine.mainMixerNode, format: format)
}
non-public func setupAudioSession() {
let audioSession = AVAudioSession.sharedInstance()
do {
strive audioSession.setCategory(.playAndRecord, mode: .default, choices: [.defaultToSpeaker, .allowBluetooth])
strive audioSession.setPreferredSampleRate(AUDIO_SESSION_SAMPLE_RATE)
strive audioSession.setPreferredIOBufferDuration(0.005) // 5ms buffer for decrease latency
strive audioSession.setActive(true)
// Add observers
setupInterruptionObserver()
} catch {
audioErrorMessage = "Didn't arrange audio session: (error)"
}
}
That is all known as upon app startup so we’re able to report at any time when the consumer presses the report button.
Nonetheless, presently when this occurs, any exterior audio stops enjoying.
I remoted the difficulty to this line:
inputNode = audioEngine.inputNode
When that is commented out, the audio will play — however I clearly want this for recording performance.
Is that this a bug? Anticipated conduct?