AudioKit microphone doesn't work if permission was not granted on app launch

Viewed 54

I am facing a strange issue with AudioKit 5.2.2. If the app is launched without microphone permission granted, then the microphone wouldn't work even if the user granted permission while the app is running. It requires reopening the app after granting permission to make it work properly. The microphone doesn't throw any errors but it doesn't seem to receive any data if the permission was not granted.

I must also say that the permission is requested from the Flutter code, but if I check the permission status through native code it also returns granted status.

Also, the setup function is always called after the permission is granted.

Here is min reproducible code:

var engine: AudioEngine!
var silencer: Fader!
var mixer: Mixer!
var tracker: AmplitudeTap!


func setup() -> Bool {
    if engine == nil {
        engine = AudioEngine()
    }
    if mixer == nil {
        mixer = Mixer()
    }

    guard let input = engine.input else {
        return false
    }

    if silencer == nil {
        let silencer = Fader(input, gain: 0)
        self.silencer = silencer
    }

    engine.output = mixer

    tracker = AmplitudeTap(input) { amplitude in
        DispatchQueue.main.async {
            print("amplitude: \(amplitude)") // <- nothing is received here is the permission is not granted initially
        }
    }

    return true
}

func start() {
    do {
        try tracker.start()
        try engine.start()
    } catch let err {
        print(err)
    }
}

func stop() {
        engine.stop()
        tracker.stop()
        mixer.removeAllInputs()
        engine.output = nil
        tracker.dispose()
}
0 Answers
Related