当一次运行多个声音时,AVAudioPlayer使用EXC_BAD_ACCESS(代码= 1)使我的应用程序崩溃

时间:2015-05-19 05:02:40

标签: ios avaudioplayer multi-touch

你好我的声音播放,但如果我继续快速击中多个声音,我得到一个崩溃EXC_BAD_ACCESS(代码= 1)。一直在努力想出这个。我也试过使用属性,但没有运气。有人在播放多个同时发出的声音时曾经见过这种情况吗?

@interface SoundBoardScene : SKScene<AVAudioPlayerDelegate> 
AVAudioPlayer  *Player1;
AVAudioPlayer *Player2;
AVAudioPlayer *Player3;
AVAudioPlayer *Player4;
AVAudioPlayer *Player5;
AVAudioPlayer *Player6;
AVAudioPlayer *Player7;
AVAudioPlayer *Player8;

-(AVAudioPlayer*) PlayAudioFile:(AVAudioPlayer*)player withAudioFileName:(NSString*)audioFileName withExtensionType:  (NSString*)audioFileExtension withLoopCount:(uint)NumberOfLoops

NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]
                                     pathForResource:audioFileName
                                     ofType:audioFileExtension]];
player = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil];
player.numberOfLoops = NumberOfLoops;
return player;

}

-(void) initSounds

Player1 = [animalObject PlayAudioFile:Player1 withAudioFileName:@"Sound1" withExtensionType:@"mp3" withLoopCount:0];
 Player1.delegate=self;
Player2 = [animalObject PlayAudioFile:Player2 withAudioFileName:@"Sound2" withExtensionType:@"mp3" withLoopCount:0];
Player2.delegate=self;

etc
etc

}

if([node.name isEqualToString:@"Sound1"])
    {

            [Player1 play];

    }
if([node.name isEqualToString:@"Sound2"])
    {

            [Player2 play];

    }

1 个答案:

答案 0 :(得分:0)

没有必要使用avplayer播放声音文件。

试试这段代码

[self runAction:[SKAction repeatAction:[SKAction playSoundFileNamed:@"pew1.wav" waitForCompletion:NO] count:count]];