I have a radio streaming AVPlayer and I created a slider which controls the volume for the player.
-(void)adjustVolume
{
if (self.player != nil)
{
NSLog(@"Adjusting volume...");
self.player.volume = volumeControl.value;
NSLog(@"%f",self.player.volume);
}
}
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.
How can I do this?
LATER EDIT:
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.
audioSession = [AVAudioSession sharedInstance];
BOOL ok;
NSError *setCategoryError = nil;
ok = [audioSession setCategory:AVAudioSessionCategoryPlayback error:&setCategoryError];
volume = audioSession.outputVolume;
volumeControl.value = volume;
NSTimer *volumeTimer = [NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(updateSound) userInfo:nil repeats:YES];
and the updateSound:
- (void)updateSound{
volume = audioSession.outputVolume;
volumeControl.value = volume;
}
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.