应用程序在尝试停止iOS 6 SDK中的音频播放器时挂起

时间:2012-09-20 13:21:00

标签: objective-c xcode avaudioplayer hang ios6

在更新iOS6.0(Xcode 4.5)之前,一切都很好。 在我更新到Xcode 4.5之后,它在尝试处理[audioPlayer stop]时开始使应用程序挂起(没有崩溃); 。 我真的不知道如何解决它。有人有任何建议吗?

以下是我的代码:

- (BOOL) initBGM:(NSString *)fileName {
    if( audioPlayer != nil ) {
        [audioPlayer stop];  // App hanged!!!!!!!!!!!!!!
        [audioPlayer release];
        audioPlayer = nil;
    }
    NSBundle *bundle = [NSBundle mainBundle];
    NSString *soundPath = [bundle pathForResource:fileName ofType:@"mp3"];
    if( soundPath ) {
        NSURL *url = [NSURL fileURLWithPath:soundPath];
        NSError *error;
        audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
        audioPlayer.numberOfLoops = -1; // play sound infinitely
        audioPlayer.volume = [AppDelegate getBGMVolume];
        [audioPlayer prepareToPlay]; // minimize the lag before play
        return YES;
    } else {
        log(@"WARNING!! soundPath is missing!");
    }
    return NO;
}

0 个答案:

没有答案