What is best way of calling a sound array in different places?
My code:
//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);
As you s开发者_C百科ee I use an array finalArray
that is holding the values from a text file. I want to play a sound in three places of the code in loadView
+ nextButton
+ PreButton
.
Do I have to load the same code in the three places? Or can I make this into a method that I can just call three times?
no need to answer i think the best way is just calling it with a method like the following:
-(void) sound:(NSUInteger)s_obj;
so thank you I just tried it by myself and it works fine with one line
[self sound:s];
精彩评论