Hello,
I am working on an app with two UIButtons and one UIImageView. When button 1 is pressed I would like touches on the UIImageView to play "sound1". When button 2 is pressed I want touches on the same UIImageView to play "sound2".
Is there a way to change the pathForResouces when button 1 and button 2 are selected to "sound1" and "sound2"?
Thanks,
Nick
I am working on an app with two UIButtons and one UIImageView. When button 1 is pressed I would like touches on the UIImageView to play "sound1". When button 2 is pressed I want touches on the same UIImageView to play "sound2".
Code:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch = [[event allTouches] anyObject];
CGPoint location1 = [touch locationInView:touch.view];
if(CGRectContainsPoint(image1.frame, location1))
{ [image1 setHighlighted:YES];
NSString *path = [[NSBundle mainBundle] pathForResource:@"sound1" ofType:@"wav"];
myMusic=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
[myMusic play];
}else {
[image1 setHighlighted:NO];
}
Is there a way to change the pathForResouces when button 1 and button 2 are selected to "sound1" and "sound2"?
Thanks,
Nick