Ahh, then you've already got myAction hooked up to a button in your view? If so, I'd do the code for more like this (Note that I'm not compiling this, so I might have some syntax errors, sorry...):
THE .h file
Code:
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <AVFoundation/AVAudioPlayer.h>
@interface MainView :UIView {
// the player
AVAudioPlayer* theAudio;
}
- (IBAction)myAction:(id)sender;
@end
The source file:
Code:
#import "MainView.h"
@implementation MainView
- (IBAction)myAction:(id)sender {
if (theAudio == nil) {
// Set up the player.
NSString *path = [[NSBundle mainBundle] pathForResource:@"boom" ofType:@"wav"];
theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPathath] error:NULL];
theAudio.delegate = self;
[theAudio play];
}
else if ([theAudio isPlaying]) {
// there's no point in stopping it, if it's not playing...
[theAudio stop];
}
/* Uncomment this if you want the button to start the sound again...
else {
[theAudio play];
}
*/
}
@end
... at least I hope that this is close. To what you want. I didn't realize that you were using myAction as the target for the button. Also, note that this board seems to be automatically replacing colon open paren

with a frowny face...