编辑布尔节能问题
我有我的应用程序一个声音,开始时,应用程序开始玩。另外我有两个方法来播放和停止的声音:
-(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"]; }
现在我已经得到了不同viewControllers和我MAINVIEW有一个按钮,停止/启动音乐(取决于wheter音乐播放或不)。
所以我有:
-(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...
}
}
现在有一个问题。声音在应用程序启动时播放,之后我可以按下按钮并停止声音,但之后我无法再次启动它。我已经把NSLogs放在代码中,看到按下stopButton之后BOOL仍然没有。
我的错误在哪里?
确实没有答案,你应该做这个评论。我试了这个,这是好的。布尔具有应有的价值,我认为问题在另一点上。 – Leon 2011-04-07 22:32:39
@Leon:你是对的。这是为了引导你找到一个解决方案,而这个解决方案并不完全属于“答案”的定义。我的印象是你希望人们试图帮助你,我认为这可能实际上解决了你的问题,但你显然更关心他们是否正确地遵循了规范。 – 2011-04-07 22:52:49