2012-11-05 185 views
1

這很奇怪,我的應用在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,它就可以工作。不知道爲什麼。希望這有助於某人。

回答

1

找到了一個永久的解決方案。您可以在iPhone和iPad上使用mp3,但必須非常小心比特率。我只是設置兩個比特率爲「正常」(〜128kbits/s),它的工作原理。 希望這有助於。

相關問題