在不同的地方调用声音数组的最佳方法是什么?

时间:2011-04-06 20:14:53

标签: arrays cocoa audio

我的代码:

//Get the filename of the sound file:
NSString *path = [[NSBundle mainBundle] pathForResource: [finalArray objectAtIndex:s]  ofType:@"wav"];
//declare a system sound id
SystemSoundID soundID;

//Get a URL for the sound file
NSURL *filePath = [NSURL fileURLWithPath:path isDirectory:NO];

//Use audio sevices to create the sound
AudioServicesCreateSystemSoundID((CFURLRef)filePath, &soundID);

//Use audio services to play the sound
AudioServicesPlaySystemSound(soundID);

如您所见,我使用一个数组finalArray来保存文本文件中的值。我想在loadView + nextButton + PreButton的代码的三个位置播放声音。

我必须在三个地方加载相同的代码吗?或者我可以将其变成一种我可以调用三次的方法吗?

1 个答案:

答案 0 :(得分:0)

无需回答我认为最好的方法是使用以下方法调用它:

-(void) sound:(NSUInteger)s_obj;

非常感谢你,我自己尝试过,一行就可以了。

[self sound:s];
相关问题