Basically I want to create 48 button outlets. I have created the buttons in the interface builder and I want to be able to connect them to the outlets.
I need to be able play a sound when I press one of the buttons. But the sound file that is played should be customizable.
I want smth like:
//first create the outlets
for(int i=1;i<49;i++){
IBOutlet UIButton [Nstring of type (@"but%d"), i];
[add butt"i" to array];
}
//then connect the outlets to the buttons
//listen for buttons pressed
while(1){ //or the listener equivalent don't know exactly how i works
for(int i=1;i<49;i++){
if(array[i].pressed==TRUE){
//if button is pressed play the according file
playsound(sounds[i]);
}
}
}
I need to be able to easily change the file that is played
Thank you
You probably need more practice with Xcode/Objective-C basics and idioms.
Your approach is not valid (for instance, on iOS, we don’t loop (while(1)) to listen for events).
Find some books, and you will be able to make your own soundboard soon.
If you want to persist, here is some hints :
Assuming you place manually your buttons on the XIB view.
Assign differents tag (for instance from 1000 to 1048) to every buttons and bind them with an action :
Then you need to implement the action :
Create a property for self.audio (@property in your .h and @synthesize in your .m).
Rename your 48 sounds with name from 1000.mp3 to 1048.mp3, and add them in your project.
Add the framework AVFoundation.framework (target->build phase->Link binaries with librairies-> +).
When you click on button with tag N, it will play the sound with the name N.mp3.
Good luck