Edited
i've got a sound in my app which begins to play when the app is started. further I've got two method to play and stop the sound:
-(void)playBgMusic {
NSString *path = [[NSBundle mainBundle] pathForResource:@"bgmusic" ofType:@"aif"];
theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
theAudio.delegate = self;
[theAudio play];
[defaults setBool:NO forKey:@"isQuiet"]; }
-(void)stopMusic {
[theAudio stop];
[defaults setBool:YES forKey:@"isQuiet"]; }
Now I've got different viewControllers and in my mainView there's a button which stops/starts the music (depends on wheter music is playing or not).
So I've got:
-(IBAction)check {
isquiet = [defaults boolForKey:@"isQuiet"];
if (isquiet == YES) {
[self playBgMusic];
// Change button to indicate music is playing
}
else {
[self stopMusic];
// Change the button to indicate music has stopped...
}
}
Now there's a problem. The sound plays when the app is started, after that I can press the button and the sound is stopped but then I cant start it again. I've put NSLogs in the code and saw that the BOOL is still NO after pressing the stopButton.
Where's my mistake?