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

PS: I also post this question in StackOverflow.

Comments

  • I found the solution: to start the audioController. I used this:

    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")
    }
    
  • can u learn me how can i use TAAE with swift please?

  • not working for me... my code is below
    import UIKit
    import TheAmazingAudioEngine

    class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    @IBAction func kaydet(sender: AnyObject) {
        do {
            let audioController = AEAudioController(audioDescription: AEAudioController.nonInterleavedFloatStereoAudioDescription())
            let file = NSBundle.mainBundle().URLForResource("sample", withExtension: "wav")!
            let channel = try AEAudioFilePlayer(URL: file)
            audioController?.addChannels([channel])
            try audioController!.start()
        } catch {
            print("Failure")
        }    }
    

    }

    i tabbed once show me this but not playing :(

    2016-01-23 17:56:59.967 seskaydet[4929:251664] TAAE: Setting audio session category to AVAudioSessionCategoryPlayback
    2016-01-23 17:56:59.988 seskaydet[4929:251664] TAAE: Audio session initialized (input available, audio route 'Hoparlör') HW samplerate: 44100
    2016-01-23 17:57:00.025 seskaydet[4929:251664] TAAE: Engine setup
    2016-01-23 17:57:00.057 seskaydet[4929:251664] TAAE: Starting Engine
    2016-01-23 17:57:00.201 seskaydet[4929:251664] TAAE: Stopping Engine

  • This works

    do {
    let audioController = AEAudioController(audioDescription: AEAudioController.nonInterleavedFloatStereoAudioDescription())

    try audioController!.start()

        let file = NSBundle.mainBundle().URLForResource("sample", withExtension: "wav")!
        let channel = try AEAudioFilePlayer(URL: file)
        audioController?.addChannels([channel])
    } catch {
        print("Failure")
    }    }
    

    You need to start the Controller before you play or add channels :)

Sign In or Register to comment.