I have using AVAudioPlayer in my app but the problem is that when i play the song from list it will played while before stopping the song i am again goes to song list then select another song then both song will start playing simultaneously so please tell me the code which will terminate my first song.
I use flag variable for initializing the song file---
fileURL = [[NSURL alloc] initFileURLWithPath: [[NSBundle mainBundle] pathForResource:@" Om Namo" ofType:@"aac"]]; self._player = [[AVAudioPlayer alloc] initWithContentsOfURL:fileURL error:nil]; if (self._player) { _fileName.text = [NSString stringWithFormat: @"%@ (%d ch.)", [[self._player.url relativePath] lastPathComponent], self._player.numberOfChannels, nil]; [self updateViewForPlayerInfo]; [self updateViewForPlayerState]; }
[fileURL release]; break;
Play and push function---
- (void)startPlayback {
if ([self._player play]) { //[self stop]; [self updateViewForPlayerState]; self._player.delegate = self; } else NSLog(@"Could not play %@\n", self._player.url); }
- (void)pausePlayback { [self._player pause]; [self updateViewForPlayerState]; }
I also make stop function---
-(void)stop { [_player release]; self._player=nil; }
Please help me . Is correct my stop function. and where i put our stop function or any other solution to fix this problem...