1

这很奇怪,我的应用在 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];

加载歌曲标题

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 就可以了。不知道为什么。希望这可以帮助某人。

4

1 回答 1

1

Found a permanent solution. You can use mp3's for both iPhone and iPad but you have to be very careful with the bit rates. I just set both bit rates as "normal" (~128kbits/s) and it works. Hope this helps.

于 2013-03-12T11:41:51.150 回答