使用此代码制作随机声音可以播放动作,而不是完全确定如何命名我的声音文件。谢谢你的帮助。使用Xcode播放随机声音
int randomNumber = arc4random() % 24 + 1;
NSURL *soundURL = [NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:[NSString stringWithFormat:@"Sound%02d", randomNumber] ofType:@"mp3"]];
AVAudioPlayer * soundPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:soundURL error:nil];
[soundPlayer prepareToPlay];
[soundPlayer play];
你不是你自己写的代码? – borrrden 2012-04-06 03:08:03
不,我搜索“如何播放随机声音”只是不知道如何使用它。 – 2012-04-06 03:15:59
欢迎来到Stack Overflow。这种态度不会让你的问题得到解答。我建议你阅读FAQ部分。 – 2012-04-06 03:27:53