簡體   English   中英

AudioKit崩潰-如何播放音頻文件?

[英]AudioKit crash - How to play audio file with it?

我正在嘗試播放聲音文件,例如/ Users / NEO / Library / Developer / CoreSimulator / Devices / D21A7767-E6F6-4B43-A76B-DC6E0F628B16 / data / Containers / Data / Application / 3F8A82F6-739F-40EA-BEA9- DF3560D0D8BB /文檔/記住,When.mp3

我正在使用AudioKit / Swift 3,這是我的代碼:

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

    }

Xcode崩潰和控制台表示:由於未捕獲的異常'com.apple.coreaudio.avfaudio'而終止應用程序,原因:'所需條件為假:_engine-> IsRunning()'

我試過了AVAudioFoundation,所以效果很好。

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)
    }

你能給我一個建議嗎?

我相信,無論何時您收到“要求的條件為假:_engine-> IsRunning()”,AudioKit引擎都尚未啟動。 因此,在播放之前調用AudioKit.start()應該可以解決您的問題

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM