title: iOS - How to implement seektotime in AVPlayer (Play song from URL)?
body: <p>I want to implement Scrubber (UISlider) in AVPlayer. I have tried but I did not success completely (sometimes slider bar show incorrect value or sometimes progress timing bar). Any suggestion will be great. </p>
  
  <pre><code>-(void)playButtonClicked
  {
  
      // checks internet connnection : working or not
  
      if([InternetUtility testInternetConnection])
  
      {
  
          if (audioButton.selected)
          {
              audioButton.selected = NO;
              printf("\n\ndo audioButton.selected = NO; \n\n");
  
          }
  
          else
          {
              printf("\n\ndo audioButton.selected = YES; \n\n");
              audioButton.selected = YES;
          }
  
          if (!isAlredayPlaying) {
          printf("\n\nStarted song from 0\n");
          isAlredayPlaying=YES;
  
  
  
  
          NSURL *url = [NSURL URLWithString:AUDIO_FILE_URL];
  
  
          playerItem = [AVPlayerItem playerItemWithURL:url];
  
  
  
          player = [AVPlayer playerWithPlayerItem:playerItem];
          player.volume=5.0;
          [self.audioSliderBar setMinimumValue:0.0];
          nsTimer=[NSTimer scheduledTimerWithTimeInterval:1.0/60.0 target:self selector:@selector(updateTime:) userInfo:nil repeats:YES];
          [player play];
  
  
      }
  
      else
      {
          if (isCurrentlyPlaying)
  
          {
              [nsTimer invalidate];
              isCurrentlyPlaying=NO;
              [player pause];
  
  
          }
          else
          {
              nsTimer=[NSTimer scheduledTimerWithTimeInterval:1.0/60.0 target:self selector:@selector(updateTime:) userInfo:nil repeats:YES];
              isCurrentlyPlaying=YES;
              [player play];
  
          }
  
       }
  }      // internet connection check funtion, ended
  
  
      else {
          [ViewUtilities showAlert:INTERNET_CONNETION_TITLE :INTERNET_CONNECTION_MESSAGE];
  
      }
  }
  
      - (void)updateTime:(NSTimer *)timer {
  
  
      currentTime = CMTimeGetSeconds(playerItem.currentTime);
  
      duration = CMTimeGetSeconds(playerItem.duration);
  
  
      if (currentTime==duration) {
          [self itemDidFinishPlaying];
  
      }
  
      [ self.audioSliderBar setValue:(currentTime/duration)];
  
      float minutes = floor(currentTime/60);
      seconds =currentTime - (minutes * 60);
  
      float duration_minutes = floor(duration/60);
      duration_seconds =
      duration - (duration_minutes * 60);
  
  
  
      NSString *timeInfoString = [[NSString alloc]
                                  initWithFormat:@"%0.0f:%0.0f",
                                  minutes, seconds ];//],
      //duration_minutes, duration_seconds];
  
      if  (!(player.currentItem &amp;&amp; player.rate != 0 )&amp;&amp; isCurrentlyPlaying)
      {
          if (audioPlayerWillStop) {
  
              isAlredayPlaying=NO;
              [nsTimer invalidate];
  
          }
  
          else {
  
              [player play];
              printf("\n\n\n Force to play song...");
  
          }
  
  
      }
      self.audioCurrentTimeLabel.text = timeInfoString;
  
  }
  </code></pre>
  
  <p>- (IBAction)audioPlayerValueChanged:(UISlider *)aSlider {</p>
  
  <pre><code> CMTime newSeekTime = CMTimeMakeWithSeconds(aSlider.value*seconds,1) ;
  [player seekToTime:newSeekTime];
  </code></pre>
  
  <p>// <strong>This code not working fine completely</strong> (slider value goes back up continuously) Please help </p>
  
  <pre><code>}
  </code></pre>