简体   繁体   中英

How to playback an audio file with TheAmazingAudioEngine with Swift?

I need to playback a single audio file with TheAmazingAudioEngine framework and Swift . I'm completely newbie with this framework and tried the code below, but the audio didn't play. What is wrong? How could I play the audio file?

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

I missed to start the 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")
}

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