title: AVPlayer volume control with slider and iphone buttons
body: <p>I have a radio streaming AVPlayer and I created a slider which controls the volume for the player.</p>
  
  <pre><code>-(void)adjustVolume
  {
      if (self.player != nil)
      {
          NSLog(@"Adjusting volume...");
          self.player.volume = volumeControl.value;
           NSLog(@"%f",self.player.volume);
      }
  }
  </code></pre>
  
  <p>I need to connect the value from the slider to the values I have when pushing the volume buttons. So for example if I move the slider to 50% and after that I push the volume up button on the side of the phone, I need it to increase from 50%, as that was the volume I've set through the slider.</p>
  
  <p>How can I do this? </p>
  
  <p>LATER EDIT:</p>
  
  <p>With this code I managed to update the slider as i press the volume keys, but I can't drag the slider anymore since it always updates with the system volume. </p>
  
  <pre><code>audioSession = [AVAudioSession sharedInstance];
  BOOL ok;
  NSError *setCategoryError = nil;
  ok = [audioSession setCategory:AVAudioSessionCategoryPlayback error:&amp;setCategoryError];
  
  volume = audioSession.outputVolume;
  volumeControl.value = volume;
  NSTimer *volumeTimer = [NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(updateSound) userInfo:nil repeats:YES];
  </code></pre>
  
  <p>and the updateSound:</p>
  
  <pre><code>- (void)updateSound{
      volume = audioSession.outputVolume;
      volumeControl.value = volume;
  }
  </code></pre>
  
  <p>How can i change the system volume when I move the slider? I tried to give a value to audioSession.outputVolume but of course, it doesn't work that way.</p>