You can initiate playback like so:
player.play()
You can pause playback like so:
player.pause()
Pausing keeps the player’s current time, when you hit
play()
again it will resume from where it left off
You can stop playback like so:
player.stop()
Stopping resets the player’s current time, when you hit
play()
again it will resume from its beginning
You can check to see whether or not a player is currently playing, like this:
if player.playing {
//do stuff
}
let audioPlayer = AudioPlayer("C4Loop.aif")!
override func setup() {
audioPlayer.loops = true
pause() //call this to change the bg color!
canvas.addTapGestureRecognizer { locations, center, state in
self.audioPlayer.playing ? self.pause() : self.play()
}
}
func play() {
canvas.backgroundColor = C4Blue
audioPlayer.play()
}
func pause() {
canvas.backgroundColor = C4Pink
audioPlayer.pause()
}