简体   繁体   中英

AudioKit crash - How to play audio file with it?

I'm trying to play a sound file such as /Users/NEO/Library/Developer/CoreSimulator/Devices/D21A7767-E6F6-4B43-A76B-DC6E0F628B16/data/Containers/Data/Application/3F8A82F6-739F-40EA-BEA9-DF3560D0D8BB/Documents/Remember-When.mp3

I'm using AudioKit/Swift 3, here are my code:

do {
        debugPrint(sound.filePath)
        let audioFile = try AKAudioFile(forReading: URL(fileURLWithPath: sound.filePath))
        player = try AKAudioPlayer(file: audioFile)
        player.play()
    }catch let exception {

    }

the Xcode crash and console said: Terminating app due to uncaught exception 'com.apple.coreaudio.avfaudio', reason: 'required condition is false: _engine->IsRunning()'

I tried with AVAudioFoundation so It's work well.

do {
        player = try AVAudioPlayer(contentsOf: URL(fileURLWithPath: sound.filePath))
        guard let player = player else { return }

        player.prepareToPlay()
        player.play()
    } catch let error {
        print(error.localizedDescription)
    }

Could you give me an advise ?

I believe when ever you receive "'required condition is false: _engine->IsRunning()'" the AudioKit engine hasn't been started yet. So calling AudioKit.start() prior to playing should solve your issue

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