Skip to content

Instantly share code, notes, and snippets.

@avazquezpr
Last active August 17, 2016 18:42
Show Gist options
  • Save avazquezpr/76cf23cac35fedc5dc3f374782a8d918 to your computer and use it in GitHub Desktop.
Save avazquezpr/76cf23cac35fedc5dc3f374782a8d918 to your computer and use it in GitHub Desktop.
Slowly raise volume when alarm starts becomes active.
override func viewDidLoad() {
super.viewDidLoad()
// Timer used to raise volume
volumeTimer = NSTimer.scheduledTimerWithTimeInterval(2, target: self, selector: #selector(AlarmControlViewController.raiseVolume), userInfo: nil, repeats: true)
}
func raiseVolume() {
// Next volume level | 0.0 -> 1.0
let newVolume = (player?.volume)! + 0.1
let maxVolume = SPTVolume.abs(1.0)
// If alarm is is playing and it's volume is not max
if (player?.isPlaying == true && player?.volume != maxVolume) {
// Increment sound level
player?.setVolume(SPTVolume.abs(newVolume), callback: nil)
} else if (player?.volume == maxVolume) {
// Invalidate timer once max volume level is reached
volumeTimer?.invalidate()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment