AVAudioPlayer在ipad模拟器上崩溃,但在iPhone模拟器上工作正常

时间:2012-11-05 06:47:13

标签: ios-simulator avaudioplayer

这很奇怪,我的应用程序在iPhone(模拟器和设备)上工作正常,但在ipad模拟器上崩溃。该错误始终指向prepareToPlay方法。当我采用该方法时,然后指向播放方法。调试区域不显示任何错误或警告。我唯一的领导是方法树,但我无法找到解决方案。顺便说一句音频文件是mp3

任何帮助将不胜感激。

_ 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 = @"";
    }

更新:我已经让它工作,只使用WAV文件而不是mp3,它只是工作。不知道为什么。希望这有助于某人。

1 个答案:

答案 0 :(得分:1)

找到永久解决方案。你可以在iPhone和iPad上使用mp3,但你必须非常小心比特率。我只是将两个比特率设置为“正常”(~128kbits / s)并且它可以工作。 希望这会有所帮助。