I am new to iPhone-Development.
I want to play sound while listening to UIButton. I tried the following:
ViewController.h:
@interface JahrenzeitenViewController : UIViewController <AVAudioPlayerDelegate> { UIButton *button_PlaySound; AVAudioPlayer *audioPlayer; } @property (nonatomic, retain) IBOutlet UIButton *button_PlaySound;
ViewController.m
- (IBAction)playSound { //[audioPlayer release]; //audioPlayer = nil; NSString *audioFilePath = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"wav"]; NSURL *audioFileURL = [NSURL fileURLWithPath:audioFilePath]; NSError *error = nil; audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:audioFileURL error:&error]; [audioPlayer setDelegate:self]; [audioPlayer prepareToPlay]; [audioPlayer play]; if (audioPlayer == nil) NSLog(@"Error playing sound. %@", [error description]); else [audioPlayer play];
If I try to run the application, I get the following error:
Undefined characters for i386 architecture: "_OBJC_CLASS _ $ _ AVAudioPlayer" referenced: objc-class-ref in JahrenzeitenViewController.o ld: character not found for architecture i386 collect2: ld returned 1 exit status
I also tried changing the line
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:audioFileURL error:&error];
to
audioPlayer = [audioPlayer initWithContentsOfURL:audioFileURL error:&error];
Then I do not get the error above, but it still does not play, and I get DebugMessage from my NSLog in "playSound" -Method:
Error playing sound. (Null)
I hope you help me. Thanks in advance:)
Kevin glier
source share