I have a simple app that is supposed to play a audio file. Whenever I load a mp3 file to my NSURL is works fine and the AVAudioPlayer gets to play the song. However, when I change to a m4a file, the NSString path returns nil, like it is not able to find the path to my file, and thus the NSURL is not formed. The m4a file is of course there, in the project. It follows below the code, but I don't think is a code issue. Any ideias? Thanks.
NSString *path = [[NSBundle mainBundle] pathForResource:@"end" ofType:@"m4a"];
NSURL *urlFile = [NSURL fileURLWithPath:path];
NSError *error;
soundPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:urlFile error:&error];
if (error)
{
NSLog(@"Error in audioPlayer: %@",[error localizedDescription]);
} else {
soundPlayer.delegate = self;
[soundPlayer prepareToPlay];
[soundPlayer play];
}
Check your Target's Build Phases, if your m4a file is not listed under Copy Bundle Resources phase group, add it, then Clean, and Run again.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With