Last active
August 17, 2016 18:42
-
-
Save avazquezpr/76cf23cac35fedc5dc3f374782a8d918 to your computer and use it in GitHub Desktop.
Slowly raise volume when alarm starts becomes active.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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