Audio engine stops right away (Swift)

Hi guys,

we are relatively new to iOS development and this problem has been a huge pain.
Following this thread and multiple StackOverflow threads we think we've got the right code but for some reason the audio never plays and according to the console the engine stops right away.

`@IBAction func Play1(sender: AnyObject) {

  print("one")
  do {
        let audioController = AEAudioController.init(audioDescription: AEAudioStreamBasicDescriptionNonInterleaved16BitStereo)
        print("s")
        try audioController!.start()
        print("s1")
        let beat = NSBundle.mainBundle().URLForResource("sample", withExtension: "wav")!
        let channel = try AEAudioFilePlayer(URL: beat)
        print("s2")
        audioController?.addChannels([channel])

    } catch {
        print("Failure")
    }

}`

and this is the output from the console:

one
2016-03-17 16:30:09.090 Segno2[31636:3365229] TAAE: Audio session initialized (input available, audio route '') HW samplerate: 44100
2016-03-17 16:30:09.492 Segno2[31636:3365229] TAAE: Engine setup
s
2016-03-17 16:30:09.492 Segno2[31636:3365229] TAAE: Starting Engine
s1
s2
2016-03-17 16:30:10.817 Segno2[31636:3365229] TAAE: Stopping Engine

We have tried this multiple times with many variations on the emulator and on an iPhone 5S (newest iOS, 9.21)
We also updated Xcode to 7.2.

If someone could help us we would be forever grateful.

Cheers

Comments

  • That's happening because your instance is going out of scope. You need to store it as a member variable of a controller class.

Sign In or Register to comment.