I have set music file on button click in the memory game application.
Music is properly played, for some time but after the number of the buttons click looses the sound effect from the applcation.
-(void)setButtons_AsPerTheMatrixSelection
{
for ( i = 0 ; i < cv ; ++i )
{
for ( j = 0 ; j < ch ; ++j )
{
btnMatrix = [[[UIButton alloc] initWithFrame:CGRectMake(10+pw*j, 51+ph*i, width, height)] autorelease];
btnMatrix.tag = i*ch+j;
btnMatrix.userInteractionEnabled = TRUE;
bulImageStatus = FALSE;
[btnMatrix addTarget:self action:@selector(changeImage:) forControlEvents:UIControlEventTouchUpInside];
[btnMatrix setImage:imgDefaultBG forState:UIControlStateNormal];
[viewWithButtons addSubview:btnMatrix];
[arrButton addObject:btnMatrix];
}
}
}
-(void)changeImage:(id)sender
{
NSString *musicPath = [[NSBundle mainBundle] pathForResource:@"ding" ofType:@"mp3"];
if (musicPath)
TapSoud = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:musicPath] error:nil];
[TapSoud setDelegate:self];
[TapSoud prepareToPlay];
[TapSoud play];
}
This is working perfectly for number of presses but after certain click i am not able to play this button click tone.
what can be the issue & how can be solved this issue.
Is there any other way to play audio file?
Please suggest the appropriate solution.
Thanks.
AVAudioPlayer is alloced over and over but never released.
try this.
}