Advertisement
Guest User

Untitled

a guest
Jul 26th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. @IBAction func switchSelection(_ sender: UIButton) {
  2. if startStopButton.currentTitle! == "Start" {
  3. startStopButton.setTitle("Stop", for: UIControlState())
  4.  
  5. do {
  6. switch theAlertType {
  7. case 1:
  8. self.audioPlayer = try AVAudioPlayer(contentsOf: alert1)
  9.  
  10.  
  11. default:
  12. self.audioPlayer = try AVAudioPlayer(contentsOf: alert2)
  13.  
  14. }
  15.  
  16. pickerView.isUserInteractionEnabled = false
  17. alertTypeSegmentedControl.isEnabled = false
  18.  
  19. self.playAlert()
  20. self.theTimer.invalidate()
  21. self.theTimer = Timer.scheduledTimer(timeInterval: theInterval,
  22. target: self, selector: #selector(ViewController.playAlert),
  23. userInfo: nil, repeats: true)
  24.  
  25. } catch {
  26. print("Error getting the audio file")
  27. }
  28. } else {
  29. startStopButton.setTitle("Start", for: UIControlState())
  30.  
  31. pickerView.isUserInteractionEnabled = true
  32. alertTypeSegmentedControl.isEnabled = true
  33.  
  34. self.audioPlayer.stop()
  35. self.theTimer.invalidate()
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement