kodeco.com Forums

Beginning Audio with AVFoundation Part 2: Controlling Audio

Learn how to control an audio player’s volume, panning and looping behavior, and how to use audio metering to control user interface elements.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/3879-beginning-audio-with-avfoundation/lessons/3

Warning, in swift 3 the automatic conversion code don’t work correctly. Please note you need to change the UserDefault save mechanism : replace sender.value by sender.floatvalue on OptionViewController.

 @IBAction func setVolume(_ sender: UISlider) {
    defaults.set(sender.value, forKey: "Volume")
    defaults.synchronize()
    vc.setVolume(sender.value)
    
  }
  
  @IBAction func setPan(_ sender: UISlider) {
    defaults.set(sender.value, forKey: "Pan")
    defaults.synchronize()
    vc.setPan(sender.value)
  }
  
  @IBAction func setRate(_ sender: UISlider) {
    defaults.set(sender.value, forKey: "Rate")
    defaults.synchronize()
    vc.setRate(sender.value)
  }

Hope it can help, anyway, very interesting course.
Thanks à lot