Step 2

Locate Main.storyboard click on it and find the black ViewController named "ViewController".

Drag 3 buttons name them Play, Pause, and Stop. (I think their intended purpose is clear)

Drag a label and replace the default text Label with Speed: 1.00.

Drag a slider onto the ViewController.

Finally organize it how you see fit and add Constraints.

Mine looks like this

Step 3

We are going to need Outlets for all these items.

Make sure you are still on Main.storyboard. Click on the yellow square on top of the ViewController, this will ensure you selected ViewController.

Switch to assistant Editor and Control click drag to start creating outlets for all the UI elements that are in the View Controller.

Make sure that you enter the correct Type. The slider should be UISlider and the buttons should be UIButton.

Here is what I named my outlets

@IBOutletweakvar slider: UISlider!

@IBOutletweakvar speedLabel: UILabel!

@IBOutletweakvar playButton: UIButton!

@IBOutletweakvar pauseButton: UIButton!

@IBOutletweakvar stopButton: UIButton!

We are going to need these outlets to change and access some of the attributes these UI elements have. For example we might need to disable the pause button if there is no audio playing. It wouldn't make sense to have some buttons enabled at certain times. This will save the user the hassle of figuring out what buttons her or she could press.

Step 4

Lets Create Actions for the buttons and for the slider. You create the actions the same way that you would create an outlet except that instead of Outlet choose Action.

Here are my Actions

@IBActionfunc sliderMoved(sender: UISlider) {

}

@IBActionfunc playAudio(sender: UIButton) {

}

@IBActionfunc pauseButton(sender: UIButton) {

}

@IBActionfunc stopButton(sender: UIButton) {

}

When the slider is moved @IBActionfunc sliderMoved(sender: UISlider) will be triggered.

The buttons work in a similar way except that the action is triggered when a user presses the button.

Step 5

Lets load up some audio.

Drag an audio clip into the Supporting Files Folder on the left Navigator.

The file that I inserted into my project was named: movie_quote.mp3 .

We need to create a variable of type AVAudioPlayer in order to play and control various aspects of our audio file. (like the rate or speed )

Insert var audioPlayer:AVAudioPlayer! above or bellow your outlets. Its a good idea to group all the variable together in your code.

The next part is going to be the most complicated part of the code. Don't worry I'll do my best to explain it all.