title: How to use the rate in AVAudioEngine
body: <p>How do we use rate in AVAudioEngine?</p>
  
  <p>Here's my complete code:</p>
  
  <pre><code>import UIKit
  import AVFoundation
  
  class ViewController: UIViewController {
  
  var audioEngine = AVAudioEngine()
  var myPlayer = AVAudioPlayerNode()
  
  override func viewDidLoad() {
      super.viewDidLoad()
      if var filePath = NSBundle.mainBundle().pathForResource("music", ofType: "wav"){
  
          var filePathURL = NSURL.fileURLWithPath(filePath)
          audioEngine.attachNode(myPlayer)
          var audioFile = AVAudioFile(forReading: filePathURL, error: nil)
          var audioError:NSError?
  
          audioEngine.connect(myPlayer, to: audioEngine.mainMixerNode, format: audioFile.processingFormat)
  
          myPlayer.scheduleFile(audioFile, atTime: nil, completionHandler: nil)
          audioEngine.startAndReturnError(&amp;audioError)
  
      }else {
          println("url not found")
  
      }
  
  }
  
  
  @IBAction func playSound(sender: UIButton) {
  
      myPlayer.rate = 0.5
      myPlayer.play()
  
  }
  </code></pre>
  
  <p>So while I play the sound its not using the rate at at all. Furthermore, how do I reset the position once I am done playing the audio. AVAudioPlayer had currentTime to use to reset the bar. </p>
  
  <p>Edit1: This is rather confusing cause if AVAudioPlayerNode doesn't have a class to maintain why does it allow me to use rate at all? Sorry completely noob to programming. </p>
  
  <p>Edit2: Got it working with help from Matt's example code. I missed the audio output line:</p>
  
  <pre><code>        var audioEngine = AVAudioEngine()
          var myPlayer = AVAudioPlayerNode()
          audioEngine.attachNode(myPlayer)
          var changeAudioUnitTime = AVAudioUnitTimePitch()
  
          changeAudioUnitTime.rate = audioChangeNumber
          audioEngine.attachNode(changeAudioUnitTime)
          audioEngine.connect(myPlayer, to: changeAudioUnitTime, format: nil)
          audioEngine.connect(changeAudioUnitTime, to: audioEngine.outputNode, format: nil)
          audioPlayerNode.scheduleFile(audioFile, atTime: nil, completionHandler: nil)
          audioEngine.startAndReturnError(nil)
          audioPlayerNode.play()
  </code></pre>
  
  <p>Thanks everyone for the help.</p>