I am created an application which play multiple audio files from locally. Audio files are long. Audio player has following options for the user
* Forward,
* Rewind,
* Next Track,
* Previous Track,
I am planning to use AvAudioPlayer so that i can play an audio with long time. When i am changing the audio file ie pressing next track audio. The audioplayer instance is not getting released. This problem is appearing some times only. Please help me..!! I am help less..
Next Track Button IBAction Method
*
(IBAction) nextTrackPressed { [audioPlay stopAudio]; if (audioPlay) { audioPlay = nil; [audioPlay release]; }
appDelegate.trackSelected += 1; [self intiNewAudioFile]; [self play]; }
Initializing audio file through below method
-(void) intiNewAudioFile { NSAutoreleasePool *subPool = [[NSAutoreleasePool alloc] init];
NSString *filePath = [[NSString alloc] init];
trackObject = [appDelegate.trackDetailArray objectAtIndex:appDelegate.trackSelected];
NSLog(@"%@",trackObject.trackName);
// Get the file path to the song to play.
filePath = [[NSBundle mainBundle] pathForResource:trackObject.trackName ofType:@"mp3"];
// Convert the file path to a URL.
NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:filePath];
if (audioPlay) {
audioPlay = nil;
[audioPlay release];
}
audioPlay = [[AudioPlayerClass alloc] init];
[audioPlay initAudioWithUrl:fileURL];
[filePath release];
[fileURL release];
[subPool release];
}
AudioPlayerClass Implementation
import "AudioPlayerClass.h"
@implementation AudioPlayerClass
*
(void) initAudioWithUrl: (NSURL *) url {
curAudioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil]; [curAudioPlayer setDelegate:self]; [curAudioPlayer prepareToPlay]; }
*
(void) playAudio { [curAudioPlayer play]; }
*
(void) pauseAudio { [curAudioPlayer pause]; }
*
(void) stopAudio { [curAudioPlayer stop]; }
*
(BOOL) isAudioPlaying { return curAudioPlayer.playing; }
*
(void) setAudiowithCurrentTime

NSInteger) time { curAudioPlayer.currentTime = time; }
*
(NSInteger) getAudioFileDuration { return curAudioPlayer.duration; }
*
(NSInteger) getAudioCurrentTime { return curAudioPlayer.currentTime; }
*
(void) releasePlayer { [curAudioPlayer release]; }
*
(void)dealloc { [curAudioPlayer release]; [super dealloc]; }
@end