如何使用TheAmazingAudioEngine和Swift播放音频文件?

时间:2015-12-24 14:01:19

标签: ios swift audio the-amazing-audio-engine

我需要使用TheAmazingAudioEngine frameworkSwift播放单个音频文件。 我完全是这个框架的新手,并尝试下面的代码,但音频没有播放。怎么了?我怎么能播放音频文件?

do {
    var audioController = AEAudioController(audioDescription: AEAudioController.nonInterleavedFloatStereoAudioDescription())
    let file = NSBundle.mainBundle().URLForResource("myaudiofile", withExtension: "wav")!
    let channel = try AEAudioFilePlayer(URL: file)
    audioController?.addChannels([channel])
    channel.playAtTime(0)
} catch {
    print("Failure")
}

1 个答案:

答案 0 :(得分:1)

我错过了开始audioController

do {
    var audioController = AEAudioController(audioDescription: AEAudioController.nonInterleavedFloatStereoAudioDescription())
    let file = NSBundle.mainBundle().URLForResource("myaudiofile", withExtension: "wav")!
    let channel = try AEAudioFilePlayer(URL: file)
    audioController?.addChannels([channel])
    try audioController!.start()
} catch {
    print("Failure")
}