I’m trying to play a mp3 file in objective c with Xcode for the iPhone.
In viewDidLoad:
NSURL *mySoundURL = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/mySound.mp3", [[NSBundle mainBundle] resourcePath]]];
NSError *myError;
mySound = [[AVAudioPlayer alloc] fileURLWithPath:heartBeatURL error:&myError];
[mySound play];
I found a suggestion here: Problem while playing sound using AVAudioPlayer?
but it did not work for me, it only generated more issues.
When the program launches I get this in output and the program crashes:
Undefined symbols for architecture i386:
“_OBJC_CLASS_$_AVAudioPlayer”, referenced from:
objc-class-ref in SecondViewController.o
ld: symbol(s) not found for architecture i386
collect2: ld returned 1 exit status
What am I doing wrong here?
It looks to me like you haven’t linked the AVFoundation framework into your app.
Assuming recent enough xcode:
Here’s some working AVAudioPlayer code for comparison: