title: AVAudioEngine() Playback Not Working
body: <p>I'm trying to change the pitch of a sound using the <code>AVAudioEngine()</code> in Swift. This is my code:</p>
  
  <pre><code>func setUpEngine() {
      let fileString = NSBundle.mainBundle().pathForResource("400", ofType: "wav")
      let url = NSURL(fileURLWithPath: fileString!)
      do {
          try audioFile = AVAudioFile(forReading: url)
          print("done")
      }
      catch{
  
      }
  }
  var engine = AVAudioEngine()
  var audioFile = AVAudioFile()
  var audioPlayerNode = AVAudioPlayerNode()
  var changeAudioUnitTime = AVAudioUnitTimePitch()
  override func viewDidLoad() {
      setUpEngine()
      let defaults = NSUserDefaults.standardUserDefaults()
      audioPlayerNode.stop()
      engine.stop()
      engine.reset()
      engine.attachNode(audioPlayerNode)
      changeAudioUnitTime.pitch = 800
      engine.attachNode(changeAudioUnitTime)
      engine.connect(audioPlayerNode, to: changeAudioUnitTime, format: nil)
      engine.connect(changeAudioUnitTime, to: engine.outputNode, format: nil)
      audioPlayerNode.scheduleFile(audioFile, atTime: nil, completionHandler: nil)
      engine.startAndReturnError(nil)
      audioPlayerNode.play()
  </code></pre>
  
  <p>The rest of my code is below (I do close the brackets).
  I found most of this code online and I get an error with the line </p>
  
  <pre><code>engine.startAndReturnError(nil)
  </code></pre>
  
  <blockquote>
    <p>'Value of type has no member'.</p>
  </blockquote>
  
  <p>When I remove this line I get the following error: </p>
  
  <blockquote>
    <p>'AVAudioPlayerNode.mm:333: Start: required condition is false:
    _engine->IsRunning() Terminating app due to uncaught exception 'com.apple.coreaudio.avfaudio', reason: 'required condition is false:
    _engine->IsRunning()''</p>
  </blockquote>
  
  <p>Any help would be greatly appreciated. I am using Swift in xCode and a single view application.</p>