title: Loading AVURLAsset asynchronously in AVQueuePlayer disturbing the order - iOS
body: <p>I need to play some audios in a row, and therefore using <code>AVQueuePlayer</code> for that purpose. I'm loading audios in it as :</p>
  
  <pre><code>for (NSInteger i = row ; i&lt;_messagesArray.count ; i++)
      {
          _urlString = ((PFFile*)(_messagesArray[i][@"messageFile"])).url;
  
          AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:[NSURL URLWithString:_urlString] options:nil];
          NSArray *keys = @[@"playable"];
  
  
          AVPlayerItem *item = [AVPlayerItem playerItemWithAsset:asset];
  
          // Subscribe to the AVPlayerItem's DidPlayToEndTime notification.
          [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(itemDidFinishPlaying:) name:AVPlayerItemDidPlayToEndTimeNotification object:item];
  
  
  
          if (_queuePlayer == nil)
          {
              _queuePlayer = [[AVQueuePlayer alloc] initWithPlayerItem:item];
  
          }
          else
          {   /*This loads Async*/
              [asset loadValuesAsynchronouslyForKeys:keys completionHandler:^() {
                  [_queuePlayer insertItem:item afterItem:nil];
              }];
          }
  
      }
  
  [_queuePlayer play];
  </code></pre>
  
  <p>Now the problem is that since I'm loading the assets from URL via <code>Async</code> (See <code>else</code> condition in the code above), the order of audio files in my <code>AVQueuePlayer</code> is not same as the URLs in the <code>_messagesArray</code> </p>
  
  <p>e.g :
  <code>_messagesArray = audioURL1 , audioURL2, audioURL3</code></p>
  
  <p>then due to async, whichever loads first, goes into <code>AVQueuePlayer</code> first</p>
  
  <p><code>AVQueuePlayer = audio2 (from URL2) , audio1 (from URL1) , audio3 (from URL3)</code></p>
  
  <p><strong>Please suggest a solution to maintain the order in my player.</strong></p>
  
  <p>Thanks.</p>