I am using a simple bit of code to play an audio file:
NSString *pathToMusicFile1 = [[NSBundle mainBundle] pathForResource:@"song" ofType:@"mp3"];
mySong1 = [[AVAudioPlayer alloc]initWithContentsOfURL:[NSURL fileURLWithPath:pathToMusicFile1] error:NULL];
NSLog(@"Song1 Loaded");
mySong1.numberOfLoops = -1;
mySong1.volume = 1.0;
[mySong1 play];
I have imported AVFoundation and I have declared mySong1 in my header file and then synthesized it in my implementation file. This code works fine, for the most part. I get no errors and the audio plays great in the simulator. It also plays fine on an iPhone 3GS running 4.0 and on an original iPhone running 3.1.3. The problem is that it doesn't play on an iPhone 4 running iOS 4.1. I have tried cleaning the project as well as restarting the phone. Neither helps. I also tried an .aiff file instead of the mp3, but no luck there either.
What am I missing? Is there an alternative way to play sounds that I should be using now? Any help appreciated. Can't figure out what the problem is here. Thanks for any help.