title: How to pause a dispatch_queue_t and the queues created by it
body: <p>I'm creating a program that can, amoung other things, fade in and out music. The problem is that other threads/queues can pause the music, meaning that the fade in and out also need to not only pause, but hold off. I need to be able to pause the "timer" on a dispatch_after (because this is called when the music starts playing in order to tell it when to start fading out, which would need to be delayed if it was paused) and pause a queue itself (in order to pause a fade in or fade out WHILE they're fading in or out)</p>
  
  <p>Here's the code (fadeIn and delayFadeOut are both called at the start of the program):</p>
  
  <pre><code>- (void) doFadeIn: (float) incriment to: (int) volume with: (AVAudioPlayer*) thisplayer on: (dispatch_queue_t) queue{
      dispatch_async(queue, ^{
          double delayInSeconds = .1;
          dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
          dispatch_after(popTime, queue, ^(void){
              thisplayer.volume = (thisplayer.volume + incriment) &lt; volume ? thisplayer.volume + incriment : volume;
              NSLog([[[NSNumber alloc] initWithFloat:thisplayer.volume] stringValue]);
              if (thisplayer.volume &lt; volume) {
                  [self doFadeIn:incriment to:volume with:thisplayer on:queue];
              }
          });
      });    
  }
  
  -(void) doDelayFadeOut: (float) incriment with: (AVAudioPlayer*) thisplayer on: (dispatch_queue_t) queue
  {
      dispatch_async(queue, ^{
          double delayInSeconds = .1;
          dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
          dispatch_after(popTime, queue, ^(void){
              thisplayer.volume = (thisplayer.volume - incriment) &gt; 0 ? thisplayer.volume - incriment : 0;
              NSLog([[[NSNumber alloc] initWithFloat:thisplayer.volume] stringValue]);
              if (thisplayer.volume &gt; 0.0) {
                  [self doDelayFadeOut:incriment with:thisplayer on:queue];
              }
          });
      });
  }
  
  -(void) fadeIn: (AVAudioPlayer*) dFade {
      if (dFade == nil) {
          return;
      }
      dispatch_queue_t queue = dispatch_queue_create("com.cue.MainFade", NULL);
      dispatch_async( queue, ^(void){
          if(dFade !=nil){
              double incriment = ([self relativeVolume] / [self fadeIn]) / 10; //incriment per .1 seconds.
              [self doFadeIn: incriment to: [self relativeVolume] with:dFade on:dispatch_queue_create("com.cue.MainFade", 0)];
          }
  
      });
  }
  
  - (void) delayFadeOut: (AVAudioPlayer*) dFade { //d-fade should be independent of other threads
      if (dFade == nil) {
          return;
      }
      int timeRun = self.duration - self.fadeOut;
      dispatch_queue_t queue = dispatch_queue_create("com.cue.MainFade", NULL);
      dispatch_time_t mainPopTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(timeRun * NSEC_PER_SEC));
      printf("test");
      dispatch_after(mainPopTime, queue, ^(void){
          if(dFade !=nil){
              double incriment = ([dFade volume] / [self fadeOut])/10; //incriment per .1 seconds.
              [self doDelayFadeOut:incriment with:dFade on:dispatch_queue_create("com.cue.MainFade", 0)];
          }
  
      });
      if (self.cueType == 2) {
          [self callNext];
      }
  }
  </code></pre>