這很奇怪,我的應用在iPhone(模擬器和設備)上工作正常,但在ipad模擬器上崩潰。該錯誤總是指向prepareToPlay方法。當我拿掉那個方法然後指向播放方法。調試區域不顯示任何錯誤或警告。我唯一的領導是方法樹,但我無法找出解決方案。順便音頻文件是MP3AVAudioPlayer在ipad模擬器上崩潰,但在iPhone模擬器上工作正常
任何幫助將不勝感激。
_ viewDidLoad中 __
NSError *誤差=零; [[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 = @"";
}
更新:我找到了工作,只需要使用WAV文件,而不是MP3,它就可以工作。不知道爲什麼。希望這有助於某人。