2010-08-07 3 views
0

Я хочу воспроизвести несколько аудиофайлов (* .wav), коснувшись соответствующих UImageViews. Каждое касание UIImageView изменяет «триггерный номер» - выбранный вид. Имена аудиофайлов хранятся в массиве. Но я не могу понять, как написать метод, чтобы получить имена и играть правильные звуки, не используя метод выбора случая с резервным CodeSnippets для воспроизведения звуков:Как получить Soundfilenames из NSArray и играть?

#pragma mark - 

-(void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event 
{ 
//Soundfile names in array arrAnimalde 
arrAnimalde = [NSArray arrayWithObjects:@"Hund" ,@"Schwein" ,@"Ferkel", nil]; 

// here are some Views and their triggers 
if([touch view] == img_hund){ 
    trigAnimal = 0; 
    } 

if([touch view] == img_schwein){ 
    trigAnimal = 1; 
    } 

if([touch view] == img_ferkel){ 
    trigAnimal = 2; 
     } 

     /* here I'd like to have a method to send the triggernumber and get the 
soundnameposition in the array to play the appropriate sound e. g. "Hund.wav" wich is the first entry 
in the array : I tried something with "self.langKeys objectAtIndex:arrAnimalde" instead of the string in the following code but it 
does'nt work 
*/ 

     //Sound 
    AudioServicesCreateSystemSoundID ((CFURLRef)[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource: @"**here please the right name from the array**" ofType: @"wav"]], &soundFileObject); 
    AudioServicesPlaySystemSound (self.soundFileObject); 


} 

Или это совершенно неправильный подход к реши это?

Похожие второй вопрос: Как я могу поставить три «если ([вид сенсорного] == IMG ...» код в более короткий (выберите регистр) заявление

Спасибо, что ответили?!

ответ

0

Попробуйте это ...

[arrAnimalde objectAtIndex: trigAnimal] 

например

AudioServicesCreateSystemSoundID ((CFURLRef)[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource: [arrAnimalde objectAtIndex: trigAnimal] ofType: @"wav"]], &soundFileObject); 
+0

Большое спасибо он отлично работает - и это так легко ... – FredIce

+0

Нет проблем, но, возможно, вы захотите проверить это как ответ. – Jordan

Смежные вопросы