Probleme mit AVAudioPlayer

Ich bin neu in der iPhone-Entwicklung.

Möchte ich einen Sound Abspielen, wenn ein UIButton erschlossen. Ich habe versucht, die folgenden:

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];

Wenn ich versuche die App starte, bekomme ich die folgende Fehlermeldung:

Undefined symbols for architecture i386:
"_OBJC_CLASS_$_AVAudioPlayer", auf die dort verwiesen wird:
objc-class-ref in JahrenzeitenViewController.o
ld: symbol(s) not found for architecture i386
collect2: ld zurückgegeben, 1 exit status

Ich habe auch versucht, ändern Sie die Zeile

audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:audioFileURL error:&error];

zu

audioPlayer = [audioPlayer initWithContentsOfURL:audioFileURL error:&error];

Dann habe ich nicht den oben genannten Fehler, aber seine immer noch nicht spielen und ich bekomme die DebugMessage von meinem NSLog in die "playSound"-Methode:

Error playing sound. (NULL)

Ich hoffe Ihr könnt mir helfen. Danke im Voraus 🙂

InformationsquelleAutor Kevin Glier | 2011-03-21
Schreibe einen Kommentar