title: In AVAudioplayer multiple songs play at once.how to fix single song play at a time
body: <p>I am trying to create <code>AVAudioplayer</code> programatically.The audio player successfully playing.But i have some issues.I am displaying 12 audio items in UITableview.If i click first item that should navigate audio player view controller.And i click the play button the song will play.If i click back button the song play continuously.But if i click again same item the Audio view controller the view will display initial state like progress bar should not move and current time and song duration are empty.but song play continuously.
  And another issue is there. If i click first item that corresponding song will play.I should not click any pass button.i click back button and click second item.if i click second item the audio view controller will display.I click play button the song display.In background first song play and second song also play.This is my second issue.how to solve these two issues.please help me any body.</p>
  
  <pre><code>-(void)playOrPauseButtonPressed:(id)sender
  {
      if(playing==NO)
      {
          [playButton setBackgroundImage:[UIImage imageNamed:@"Pause.png"] forState:UIControlStateNormal];
          // Here Pause.png is a image showing Pause Button.
          NSError *err=nil;
          AVAudioSession *audioSession=[AVAudioSession sharedInstance];
          [audioSession setCategory:AVAudioSessionCategoryPlayback error:nil];
          NSLog(@"%@ %d",urlsArray,selectedIndex);
          NSString *sourcePath=[urlsArray objectAtIndex:selectedIndex];
          NSData *objectData=[NSData dataWithContentsOfURL:[NSURL URLWithString:sourcePath]];
          audioPlayer = [[AVAudioPlayer alloc] initWithData:objectData error:&amp;err];
          audioPlayer.numberOfLoops = 0;
          [audioPlayer prepareToPlay];
          audioPlayer.delegate=self;
          [audioPlayer play];
          playing=YES;
      }
      else if (playing==YES)
      {
          [playButton setBackgroundImage:[UIImage imageNamed:@"play.png"] forState:UIControlStateNormal];
          [audioPlayer pause];
          playing=NO;
      }
      if (self.audioPlayer)
      {
          [self updateViewForPlayerInfo];
          [self updateViewForPlayerState];
          [self.audioPlayer setDelegate:self];
      }
  }
  -(void)updateViewForPlayerInfo
  {
      self.songDuration.text = [NSString stringWithFormat:@"%d:%02d", (int)self.audioPlayer.duration / 60, (int)self.audioPlayer.duration % 60, nil];
      NSLog(@"%f", self.audioPlayer.duration);
      self.progressBar.maximumValue = self.audioPlayer.duration;
      self.volumeSlider.value = self.audioPlayer.volume;
  }
  -(void)updateViewForPlayerState
  {
      [self updateCurrentTime];
      if (self.updatedTimer)
      {
          [self.updatedTimer invalidate];
      }
      if (self.audioPlayer.playing)
      {
          self.updatedTimer = [NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(updateCurrentTime) userInfo:self.audioPlayer repeats:YES];
      }
  }
  -(void)updateCurrentTime
  {
      //NSLog(@"self.audioPlayer.currentTime = %f", self.audioPlayer.currentTime);
      self.currentTime.text = [NSString stringWithFormat:@"%d:%02d", (int)self.audioPlayer.currentTime / 60, (int)self.audioPlayer.currentTime % 60, nil];
      self.progressBar.value = self.audioPlayer.currentTime;
  }
  -(void)volumeSliderMoved:(UISlider *)sender
  {
      self.audioPlayer.volume=[sender value];
  }
  </code></pre>