Im getting a couple of errors here. That i cant quite figure out. Error: expected specifier-qualifier-list before [ token.
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <AVFoundation/AVAudioPlayer.h>
@interface MainView :UIView {
// the player
AVAudioPlayer* theAudio;
}
- (IBAction)myAction

id)sender;
@end
And here it's saying that I havent declared theAudio. (First use in this Function. I had some other errors but I got those out of the way. These are the only two I couldnt figure out.
@implementation MainView
- (IBAction)myAction1

id)sender {
if (theAudio == nil) {
Quote:
Originally Posted by deansx
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...
|