title: AVPlayer status AVPlayerStatusFailed not working Properly
body: <p>I am implementing AVPlayer (not AVAudioPlayer) and trying to play audio from URL. It is working fine. But as we know that sometimes we can have invalid URL (URL that does not have Audio byte). <strong>When I play audio from any URL AVPlayer status shows always AVPlayerStatusReadyToPlay</strong> which is wrong. For example : In URL part if give invalid URL like : <strong><a href="http://soundx.mp3slash.net/indian/jhankar_beats/1%28mp3pk.com%29.mp3" rel="nofollow noreferrer">http://soundx.mp3slash.net/indian/jhankar_beats/1%28mp3pk.com%29.mp3</a> (it does not works even in your browser)</strong>  and even if you give <strong><a href="https://stackoverflow.com/questions/ask">https://stackoverflow.com/questions/ask</a></strong>  or any site URL (which does not have audio bytes), AVPlayer shows always AVPlayerStatusReadyToPlay. <strong>I think in this case its status must AVPlayerItemStatusUnknown or AVPlayerStatusFailed</strong> Please help, how to know URL is invalid (AVPlayerItemStatusUnknown or AVPlayerStatusFailed) show that I can show message to user. <strong>Thanks in advance</strong> </p>
  
  <pre><code>-(void)playButtonClicked
  </code></pre>
  
  <p>{</p>
  
  <pre><code>        NSURL *url = [NSURL URLWithString:AUDIO_URL];
          [self.audioSliderBar setMinimumValue:AUDIO_SLIDER_BAR_0];
          playerItem = [AVPlayerItem playerItemWithURL:url];
          player = [AVPlayer playerWithPlayerItem:playerItem];
          player.volume=5.0;
  
  
          [player addObserver:self forKeyPath:STATUS options:0 context:nil];
  
          [playerItem addObserver:self forKeyPath:PLAY_BACK_BUFFER_EMPTY options:NSKeyValueObservingOptionNew context:nil];
          [playerItem addObserver:self forKeyPath:PLAY_BACK_LIKELY_TO_KEEP_UP options:NSKeyValueObservingOptionNew context:nil];
  
          addObserverFlag=YES;
  </code></pre>
  
  <p>}</p>
  
  <pre><code>    -(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:   (NSDictionary *)change context:(void *)context
  {
      if (object == player &amp;&amp; [keyPath isEqualToString:STATUS])
      {
          if (player.status == AVPlayerStatusFailed)
          {
  
            [ViewUtilities showAlert:AUDIO_PLAYER :AUDIO_PLAYER_FAILED_MESSAGE];
  
          }
  
          else if (player.status == AVPlayerStatusReadyToPlay)
          {
  
              else if (player.status == AVPlayerItemStatusUnknown)
          {
              [ViewUtilities showAlert:AUDIO_PLAYER :AUDIO_PLAYER_UNKNOWN];
  
          }
  
          if (!player)
          {
              return;
          }
      }
  }`
  </code></pre>