I'm not sure why my AVAudioPlayer
is always nil?
#import <AVFoundation/AVFoundation.h>
@property (nonatomic) AVAudioPlayer *audioPlayer;
@synthesize audioPlayer;
- (void)viewDidLoad {
[super viewDidLoad];
// Construct URL to sound file
NSString *path = [NSString stringWithFormat:@"%@/background-music-aac.caf", [[NSBundle mainBundle] resourcePath]];
NSURL *soundUrl = [NSURL fileURLWithPath:path];
// Create audio player object and initialize with URL to sound
NSError *audioError = nil;
self.audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:soundUrl error:&audioError];
if (audioPlayer == nil) {
NSLog(@"Error? %@", audioError);
NSLog(@"AudioPlayer: %@", audioPlayer.description);
}
I feel like I have this all set up right, but it doesn't work and I'm getting nil
/null
for the audioPlayer
.
The .caf file was the problem, thanks to Brandon for the help