我尝试关闭我的应用程序的声音效果
播放方法是'[myMusic play];
-(void)viewDidLoad {
BOOL soundIsOff = [defaults boolForKey:@"sound_off"];
//the problem is here
//xcode compiler doesn't copile this code
[myMusic play] = soundIsOff;
}
声音代码: “ ///声音效果
NSString * musicSonati = [[NSBundle mainBundle] pathForResource:@"sound" ofType:@"wav"];
myMusic = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:musicSonati] error:NULL];
myMusic.delegate = self;
myMusic.numberOfLoops = 0;
Shake API代码:
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {
if (event.subtype == UIEventSubtypeMotionShake)
//Play sound :
[myMusic play] ;
}
}
答案 0 :(得分:2)
看起来您正在尝试为方法调用分配值。这就是你得到编译器错误的原因:
[myMusic play] = soundIsOff //This does not work.
你可能想要这样的东西:
if(!soundIsOff) {
[myMusic play];
}
然而,这个问题尚不清楚,所以这就是猜测。
答案 1 :(得分:0)
我对这个问题很困惑,但如果你想要的是停止声音,那么你只需要:
[myMusic stop];
答案 2 :(得分:0)
和其他人一样,我只能猜测你想要做什么。也许你正试图这样做:
soundIsOff ? [music stop] : [music play];