I've tried to make an UISlider that controls background music volume, and whatever I set the value to should be the volume of the music. The trouble is, when I run the app in simulator, and move the slider, the volume stays that of the original volume, it doesn't update.
I am new to programming so I still need help with the basics.
Here is my viewcontroller.h:
@interface FifthViewController : UIViewController <AVAudioPlayerDelegate> {
IBOutlet UISlider *slider;
IBOutlet UIAlertView *alert;
AVAudioPlayer *theAudio;
}
-(IBAction)alertbutton;
-(IBAction)changeVolume;
@end;
and here is the viewcontroller.m:
- (void)viewDidLoad
{
NSString *path = [[NSBundle mainBundle] pathForResource:@"background music" ofType:@"mp3"];
AVAudioPlayer* theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
theAudio.delegate = self;
[theAudio play];
theAudio.numberOfLoops = -1;
theAudio.volume=slider.value;
[super viewDidLoad];
}
I have connected "slider" to a horizontal slider and the sound plays and loops. And if I set the value of the slider higher or lower in Xcode, when I run the app, the volume adjusts accordingly. But if in the app I change the value of the slider, the volume remains the same . Can anyone look at my code and tell me what I'm doing wrong and how to fix it?