tags:

views:

84

answers:

3

i try to off a sound effect on my app

play method is ' [myMusic play];

-(void)viewDidLoad {
     BOOL soundIsOff = [defaults boolForKey:@"sound_off"];
     //the problem is here 
     //xcode compiler doesn't copile this code 
     [myMusic play] = soundIsOff;

}

sound code : ' ///sound effect

 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 Code :

- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {

 if (event.subtype == UIEventSubtypeMotionShake)

  //Play sound :
  [myMusic play] ; 
 }
}
A: 

I am confused by the question, but if what you want is to stop the sound, then you just need:

[myMusic stop];
crimson_penguin
+2  A: 

Looks like you are trying to assign a value to a method call. That is why you are getting the compiler error:

[myMusic play] = soundIsOff //This does not work.

You probably want something like this:

if(!soundIsOff) {
    [myMusic play];
}

The question is unclear however, so this is a guess at this point.

Jeff B
thank you .. sorry doesn't work !
Momeks
Well, what doesn't work? Do you still get the compile error? If so, what does it say? If not, do you just not get sound? If you remove the if, and just do `[myMusic play]`, does the sound work? I am glad to help, but you need to give some information other than "it doesn't work".
Jeff B
Thank you Jeff , iam using Shake API , when user shake the device something do with sound, iam going to create an option that user can Off,On the sound via , , NSUSerDefualts the sound play with ' [myMusic play];No , the compiler doesn't get any error ! but the off/on method doesn't work !
Momeks
If you leave off the NSUserDefault value, does it work then? In other words, does [myMusic play] work by itself? Add `NSLog(@"soundIsOff value: %@", soundIsOff?@"YES":@"NO");` to your code after you erad NSUserDefaults.
Jeff B
sorry , Didn't work ! but the nslog output recognizes the value is On or Off ! i edit my post and wrote the shake API code
Momeks
So the code works without the boolean? Does the music ever play, or is it a problem with myMusic?
Jeff B
No there is not any problem with myMusic .. do you want my sample code project to solve this ?
Momeks
It might help. Can you post a bigger chunk of your code? I think you are probably missing something we can't see. Does the music not stop? Or does the music never play?
Jeff B
A: 

Like the others, I can only guess at what you want to do here. Perhaps you are trying to do this:

soundIsOff ? [music stop] : [music play];
glorifiedHacker