HI
i am making an app in which there are 30 images in a scroll view and as i scroll from one image to another a sound is being played on every image by calling a method playSound. the code is below . but when i run the code through performance tool it gives leak in audioToolbox, please help me with this AVAudio player.
Code:
-(void)playSound
{
self.view.userInteractionEnabled=FALSE;
NSLog(@"play sound called start");
NSString *myExamplePath = [[NSBundle mainBundle] pathForResource:@"ting" ofType:@"mp3"];
NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:myExamplePath];
self.soundFileURL = fileURL;
[fileURL release];
[[AVAudioSession sharedInstance] setDelegate: self];
[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryAmbient error: nil];
// Registers the audio route change listener callback function
// AudioSessionAddPropertyListener (kAudioSessionProperty_AudioRouteChange,audioRouteChangeListenerCallback, self);
// Activates the audio session.
NSError *activationError = nil;
[[AVAudioSession sharedInstance] setActive: YES error: &activationError];
AVAudioPlayer *newPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL: soundFileURL error: nil];
self.myExampleSound = newPlayer;
[newPlayer release];
[myExampleSound setDelegate:self];
[myExampleSound play];
repeatCount = [[noOfCharsArray objectAtIndex:curr_page]intValue] ;
counter = 0;
NSRunLoop *runloop = [NSRunLoop currentRunLoop];
colorTimer = [[[NSTimer alloc] init]autorelease];
colorTimer = [NSTimer timerWithTimeInterval:0.1 target:self selector:@selector(changeColor) userInfo:nil repeats:YES];
[runloop addTimer:colorTimer forMode:NSRunLoopCommonModes];
[runloop addTimer:colorTimer forMode:UITrackingRunLoopMode];
NSLog(@"play sound called end");
}
-(void)changeColor
{
NSLog(@"changeColor start");
if(counter <repeatCount)
{
NSString *myString = _name;
NSMutableArray *characters = [[NSMutableArray alloc] initWithCapacity:[myString length]];
for (int i=0; i < [myString length]; i++) {
NSString *ichar = [NSString stringWithFormat:@"%c_orange.png", [myString characterAtIndex:i]];
[characters addObject:ichar];
}
UIImageView *Ab = [self.view viewWithTag:counter+1];
Ab.image = [UIImage imageNamed:[characters objectAtIndex:counter]];
[characters release];
counter ++;
}
else
{
[colorTimer invalidate];
NSLog(@"invalidate");
btn.enabled=TRUE;
self.view.userInteractionEnabled=TRUE;
[myExampleSound stop];
}
NSLog(@"changeColor end");
}
myExampleSound is declared in .h
Thanks in advance & happy coding