title: How to show or hide activity indicator in song loading time in ios
body: <p>I am working in AVAudioplayer in iOS. I am displaying an activity indicator for loading time if a user clicks the play button. My problem is that when I click the play button the loading time activity indicator is  displayed. In playing time also activity indicator displayed that is my problem.i need to hidden activity indicator in song playing time</p>
  
  <pre><code>- (void)playOrPauseButtonPressed:(id)sender
  
  {
  
    [self.view addSubview:today_slokaText];
  
    if (playing == NO)
  
    {
  
      [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
  
      [playButton setBackgroundImage:[UIImage imageNamed:@"Pause.png"]
                            forState:UIControlStateNormal];
  
      [self.view addSubview:today_slokaText];
  
      // Here Pause.png is a image showing Pause Buttomn
  
      NSError *err = nil;
  
      if (!audioPlayer)
  
      {
  
        [self loadSongAtIndex:selectedIndex];
  
        playing = YES;
      }
  
      if (err)
  
      {
  
        NSLog(@"Error %ld,%@", (long)err.code, err.localizedDescription);
      }
  
      NSTimeInterval bufferDuration = 0.005;
  
      [audioSession setPreferredIOBufferDuration:bufferDuration error:&amp;err];
  
      if (err)
  
      {
  
        NSLog(@"Error %ld, %@", (long)err.code, err.localizedDescription);
      }
  
      double sampleRate = 44100.0;
  
      [audioSession setPreferredSampleRate:sampleRate error:&amp;err];
  
      if (err)
  
      {
  
        NSLog(@"Error %ld, %@", (long)err.code, err.localizedDescription);
      }
  
      [audioSession setActive:YES error:&amp;err];
  
      if (err)
  
      {
  
        NSLog(@"Error %ld,%@", (long)err.code, err.localizedDescription);
      }
  
      sampRate = audioSession.sampleRate;
  
      bufferDuration = audioSession.IOBufferDuration;
  
      NSLog(@"SampeRate:%0.0fHZI/OBufferDuration:%f", sampleRate, bufferDuration);
  
      audioPlayer.numberOfLoops = 0;
  
      [audioPlayer prepareToPlay];
  
      [audioPlayer play];
  
      audioPlayer.delegate = self;
  
      if (!audioPlayer.playing)
  
      {
  
        [audioPlayer play];
  
        activityIndicator = [[UIActivityIndicatorView alloc]
            initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
  
        [self.view addSubview:self.activityIndicator];
  
        self.activityIndicator.center = CGPointMake(
            self.view.frame.size.width / 2, self.view.frame.size.height / 2);
  
        [self.activityIndicator startAnimating];
  
        [playButton setBackgroundImage:[UIImage imageNamed:@"Pause.png"]
                              forState:UIControlStateNormal];
  
        [bg_Image addSubview:activityIndicator];
  
      }
  
      else if (audioPlayer.playing == YES)
  
        [audioPlayer play];
  
      [self.activityIndicator stopAnimating];
  
      [playButton setBackgroundImage:[UIImage imageNamed:@"Pause.png"]
                            forState:UIControlStateNormal];
  
      playing = YES;
  
    }
  
    else if (playing == YES)
  
    {
  
      [self.activityIndicator stopAnimating];
  
      [bg_Image addSubview:activityIndicator];
  
      [playButton setBackgroundImage:[UIImage imageNamed:@"play12.png"]
                            forState:UIControlStateNormal];
  
      [self.view addSubview:today_slokaText];
  
      [audioPlayer pause];
  
      playing = NO;
  
      timer = [NSTimer
          scheduledTimerWithTimeInterval:1.0
                                  target:self
                                selector:@selector(updateViewForPlayerState)
                                userInfo:nil
                                 repeats:YES];
  
      [self.view addSubview:today_slokaText];
    }
  }
  </code></pre>