我在 Cocos2D-iPhone.org 论坛上找到了一篇关于此的帖子。虽然我并不完全理解它——但我正在努力解决它——它似乎确实解决了这个问题,至少是暂时的。他所做的就是在 CDAudioManger.m 文件中编写这个方法:
-(void) releaseBufferForFile:(NSString *) filePath {
int bufferId = [self bufferForFile:filePath create:NO];
if (bufferId != kCDNoBuffer) {
[soundEngine unloadBuffer:bufferId];
[loadedBuffers removeObjectForKey:filePath];
NSNumber *freedBufferId = [[NSNumber alloc] initWithInt:bufferId];
[freedBufferId autorelease];
[freedBuffers addObject:freedBufferId];
}
}
@end
- (void) interruption:(NSNotification*)notification
{
NSDictionary *interuptionDict = notification.userInfo;
NSNumber* interuptionTypeValue = [dict valueForKey:AVAudioSessionInterruptionTypeKey];
NSUInteger interuptionType = [interuptionTypeValue intValue];
if (interuptionType == AVAudioSessionInterruptionTypeBegan)
[self beginInterruption];
#if __CC_PLATFORM_IOS >= 40000
else if (interuptionType == AVAudioSessionInterruptionTypeEnded)
[self endInterruptionWithFlags:(NSUInteger)[interuptionDict valueForKey:AVAudioSessionInterruptionOptionKey]];
#else
else if (interuptionType == AVAudioSessionInterruptionTypeEnded)
[self endInterruption];
#endif
}
然后他换了:
AVAudioSession *session = [AVAudioSession sharedInstance];
session.delegate = self;
有了这个:
[AVAudioSession sharedInstance];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(interruption:) name:AVAudioSessionInterruptionNotification object:nil];
这是链接: http: //www.cocos2d-iphone.org/forum/topic/49956
如果我对这段代码的作用有了更好的理解,我一定会编辑这篇文章。