简体   繁体   中英

Fatal error: AudioKit: Could not start engine. When calling AudioKit.start()

I'm using AudioKit 4.0.4 with iOS 11.2

I'm using a code that is almost the same as the MicrophoneAnalysis sample project.

class FrequencyProcessor {

    var node: AKNode {
        return mic
    }

    private let mic: AKMicrophone
    private let tracker: AKFrequencyTracker
    private let silence: AKBooster

    init() {
        AKSettings.audioInputEnabled = true
        mic = AKMicrophone()
        tracker = AKFrequencyTracker(mic)
        silence = AKBooster(tracker, gain: 0)
        AudioKit.output = silence
    }


     func startRecording() {
        AudioKit.start()
     }
}

The code works perfectly in a simulator but I always get this crash when I run it on a device:

Fatal error: AudioKit: Could not start engine. error: Error Domain=com.apple.coreaudio.avfaudio Code=-10875 "(null)" UserInfo={failed call=err = AUGraphParser::InitializeActiveNodesInOutputChain(ThisGraph, kOutputChainOptimizedTraversal, *GetOutputNode(), isOutputChainActive)}.

This happens when I call startRecording.

Any idea what may be causing this issue? (I have set the "NSMicrophoneUsageDescription" in Info.plist)

edit: The audio recording session happens in a modal view which embeds an AVPlayerLayer. If I remove this AVPlayerLayer I no longer have a crash. How can I fix this issue?

edit2: I created a sample project here: https://github.com/ydemartino/MicrophoneAnalysisTest.git

It seems AudioKit doesn't want to work with AVKit: https://github.com/AudioKit/AudioKit/issues/1224

As a workaround, this is what I did:

        let item = videoPlayer.player.currentItem
        videoPlayer.player.replaceCurrentItem(with: nil)
        startAudioKit()
        videoPlayer.player.replaceCurrentItem(with: item)

Not elegant, but at least, it's no longer crashing my app...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM