This is very odd, my app works fine on the iPhone (simulator and device) but crashes on the ipad simulator. The error always points to the prepareToPlay method. When i took that method off it then points to the play method. The debug area does not show any errors or warnings. My only lead is the method tree but i can't figure out a solution. By the way audio files are mp3
Any help will be greatly appreciated.
_viewDidLoad__
NSError *error = nil; [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:&error]; //AudioSessionInitialize(NULL, NULL, NULL, NULL);
timerSong = [[AVAudioPlayer alloc] initWithContentsOfURL:alarmSong error:&error];
[self loadSongTitles];
//Make sure the system follows our playback status
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
//infinite loops
audio1.numberOfLoops = -1;
audio2.numberOfLoops = -1;
timerSong.numberOfLoops = -1;
//set volume according to volume label
[audio1 setVolume:0.5];
[audio2 setVolume:0.5];
//strat playing track(s)
[audio1 play];
[audio2 play];
loadSongsTitles
for (NSNumber *number in passingArray) {
//set the correct titles for each audio
if (number == [NSNumber numberWithInt:10]) {
firstSong = title;
NSURL *audioFileLocationURL = [[NSBundle mainBundle] URLForResource:[backgroundTracks objectAtIndex:firstSong] withExtension:@"mp3"];
audio1 = [[AVAudioPlayer alloc] initWithContentsOfURL:audioFileLocationURL error:&error];
[audio1 setDelegate:self]; //setting delagate to restart after interruptions
[audio1 prepareToPlay];
audio1Label.text = [titles objectAtIndex:title];
//when two songs selected make label empty
onlyOneAudioLabel.text = @"";
}
Update: I've got it working, just use WAV files instead of mp3 and it just works. No idea why. Hope this helps somebody.