title: Set MPVolumeView slider thumb position as device volume
body: <p>I use <a href="https://developer.apple.com/library/ios/documentation/MediaPlayer/Reference/MPVolumeView_Class/" rel="nofollow noreferrer">MPVolumeView</a> to generate a horizontal slider which allows me to manage the volume of the audio being played. It works great. However, at initialization, I want the slider <strong>takes the position corresponding to volume of the device and not 0.5</strong>, the default:</p>
  
  <p><a href="https://i.stack.imgur.com/y0buT.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/y0buT.png" alt="enter image description here"></a>
  <a href="https://i.stack.imgur.com/E7Ned.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/E7Ned.png" alt="enter image description here"></a></p>
  
  <p>Here is the code I have done:</p>
  
  <pre><code>func volumeSlider() {
  
      let parentVolumeView = MPVolumeView(frame: volumeParentView.bounds)
  
      for view in parentVolumeView.subviews {
          if (view as UIView).description.rangeOfString("MPVolumeSlider") != nil {
              mpVolumeSlider = view as! UISlider
              print("mpVolumeSlider.value : ", mpVolumeSlider.value)
  
              // Tried to set mpVolumeSlider.value to volume device, but didn't work, show : 0.0
              // mpVolumeSlider.value = AVAudioSession.sharedInstance().outputVolume
          }
          // Remove device volume indicator
          self.view!.addSubview(parentVolumeView)
      }
  
      let thumbImage = UIImage(named: "slider-image")
      slider?.setThumbImage(thumbImage, forState: .Normal)
  }
  </code></pre>