jonasalbert
12/20/2017 - 5:16 AM

volume get and set

  var Volume : Float {
    get {
      do{
        let audioSession = AVAudioSession.sharedInstance()
        try audioSession.setActive(true)
        let audioVolume =  audioSession.outputVolume
        let audioVolumePercentage = audioVolume * 100.0
        return audioVolumePercentage
      }catch{
        print("Error while getting volume level \(error)")
      }
      return 0.0
    }
    set {
      let volumeView = MPVolumeView()
      if let view = volumeView.subviews.first as? UISlider {
        view.value = Float(newValue) / 100.0
      }
    }
  }