title: How to know when AVPlayerItem is playing
body: <p>I am having a problem with <code>AVPlayerItem</code> and <code>AVQueuePlayer</code>. Currently i have a lot of music files which are 1-2 sec long and a queue Player for playing them in sequence.</p>
  
  <p>What I want is to know when a music file <strong>has just started playing</strong> and not when it has finished playing(via <code>AVPlayerItemDidPlayToEndTimeNotification</code>).</p>
  
  <p>This is because i want to run a function when a new file is loaded and played.</p>
  
  <p>My code:</p>
  
  <pre><code> for (NSUInteger i = 0; i &lt; [matchedAddr count]; i++)
  {
      NSString *firstVideoPath = [[NSBundle mainBundle] pathForResource:[matchedAddr objectAtIndex:i] ofType:@"wav"];
      //NSLog(@"file %@",firstVideoPath);
      avitem=[AVPlayerItem playerItemWithURL:[NSURL fileURLWithPath:firstVideoPath]];
      [[NSNotificationCenter defaultCenter] addObserver:self
                                               selector:@selector(currentItemIs:)
                                                   name:AVPlayerItemDidPlayToEndTimeNotification
                                                 object:avitem];
  
      [filelist addObject:avitem];
  }
   player = [AVQueuePlayer queuePlayerWithItems:filelist];
  [player play];
  
  
  - (void)currentItemIs:(NSNotification *)notification
  {
      NSString *asd=[seqArray objectAtIndex:currentColor];
      currentColor=currentColor+1;
      AVPlayerItem *p = [notification object];
      [p seekToTime:kCMTimeZero];
  
      if([asd isEqual:@"1"])
      {
          [UIView animateWithDuration:0.01 animations:^{
             one.alpha = 0;
          } completion:^(BOOL finished) {
  
              [UIView animateWithDuration:0.01 animations:^{
                 one.alpha = 1;
              }];
          }];
      }
  }
  </code></pre>
  
  <p>As you can see,the <code>currentItemIs</code> void is called but it runs when the track has finished playing.I want to be called when the track is at the beginning.</p>
  
  <p><strong>EDIT:</strong>
  Updated version of Winston's snippet:</p>
  
  <pre><code>NSString * const kStatusKey         = @"status";
  
          [avitem addObserver:self
                                forKeyPath:kStatusKey
                                   options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew
                                   context:@"AVPlayerStatus"];
  - (void)observeValueForKeyPath:(NSString *)path
                        ofObject:(id)object
                          change:(NSDictionary *)change
                         context:(void *)context {
  
      if (context == @"AVPlayerStatus") {
  
          AVPlayerStatus status = [[change objectForKey:NSKeyValueChangeNewKey] integerValue];
          switch (status) {
              case AVPlayerStatusUnknown: {
  
              }
                  break;
  
              case AVPlayerStatusReadyToPlay: {
                  // audio will begin to play now.
                  NSLog(@"PLAU");
                  [self playa];
              }
                  break;
          }
      }
  }
  </code></pre>