大家好,我有一个问题,当我点击另一个控制器上的按钮时,为什么我的声音不会停止
FirstController:
- (IBAction)touchBtnA:(id)sender {
[self.settings setEnabled:NO];
if (enabledA) {
[self.BtnA setEnabled:NO];
[self.BtnB setEnabled:YES];
enabledA = NO;
enabledB = YES;
[self.BtnA setAlpha:1.0];
[self.BtnB setTextColor:[UIColor whiteColor]];
[_downButton setImage:[UIImage imageNamed:@"DownButon@2x.png"] forState:UIControlStateNormal];
[_upButton setImage:[UIImage imageNamed:@"ButonUpDown.png"] forState:UIControlStateNormal];
} else {
[self.BtnA setEnabled:NO];
[self.BtnB setEnabled:YES];
enabledA = NO;
enabledB = YES;
[self.BtnB setTextColor:[UIColor whiteColor]];
[self.BtnA setAlpha:1.0];
[_upButton setImage:[UIImage imageNamed:@"ButonUpDown.png"] forState:UIControlStateNormal];
}
NSUserDefaults *standartDefaults = [NSUserDefaults standardUserDefaults];
if ([standartDefaults stringForKey:@"editSelected"]) {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
int timeToAdd = [[defaults objectForKey:@"addTime"]intValue];
_remainingTimeA += timeToAdd;
[self updateTime:A];
}else{
}
if (_remainingTimeB < 601) {
NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/secundamer.wav",[[NSBundle mainBundle]resourcePath]]];
NSError *error;
_milescundsSound = [[AVAudioPlayer alloc]initWithContentsOfURL:url error:&error];
_milescundsSound.numberOfLoops = 1;
[_milescundsSound play];
[_clockSound stop];
}else{
NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/clock.wav",[[NSBundle mainBundle]resourcePath]]];
NSError *error;
_clockSound = [[AVAudioPlayer alloc]initWithContentsOfURL:url error:&error];
_clockSound.numberOfLoops = -1;
[_clockSound play];
[_milescundsSound stop];
}
NSURL *urlButton = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/buttonSound.wav",[[NSBundle mainBundle]resourcePath]]];
NSError *error;
buttonSound = [[AVAudioPlayer alloc]initWithContentsOfURL:urlButton error:&error];
buttonSound.numberOfLoops = 0;
[buttonSound play];
} 我在IBAction中使用声音,我需要停止来自另一个ViewController的声音。
SecondController:
- (IBAction)actionSoundMute:(id)sender {
if ([sender isSelected]) {
[sender setImage:[UIImage imageNamed:@"ВКЛ.png"] forState:UIControlStateNormal];
[sender setSelected:NO];
}else{
[sender setImage:[UIImage imageNamed:@"ВЫКЛ.png"] forState:UIControlStateNormal];
[timer.clockSound stop];
[timer.milescundsSound stop];
[sender setSelected:YES];
}
}
如果有人可以帮我解决这个问题。谢谢。