title: Switching Videos in AVPlayer Creates Flash When Changing
body: <p>I am using AVFoundation's AVPlayer to play 2 video clips made from 1 longer video (so the end of the first matches the beginning of the second)</p>
  
  <p>When the first video ends and the user taps, I create a new AVPlayer and assign it to my  PlayerView, and start playing the second clip.</p>
  
  <p>This all works, however, there is a <strong>prominent</strong> screen "flicker".</p>
  
  <p>My assumption is that this is caused by the player view removing the first clip and then showing the second clip.</p>
  
  <p>What I need is for this flicker to no appear, so that going between the two clips is seamless.</p>
  
  <p>Do anyone know if there is a way to stop this flickr, either via the AVPlayer* classes, or a way to "fake" it by doing <em>something</em> to make it so this isn't visible.</p>
  
  <p>Thanks</p>
  
  <p>Below is the code of my load and play method:</p>
  
  <pre><code>- (void)loadAssetFromFile
  {
      NSURL *fileURL = nil;
  
      switch (playingClip)
      {
          case 1:
              fileURL = [[NSBundle mainBundle] URLForResource:@"wh_3a" withExtension:@"mp4"];
          break;
  
          case 2:
              fileURL = [[NSBundle mainBundle] URLForResource:@"wh_3b" withExtension:@"mp4"];
          break;
  
          case 3:
              fileURL = [[NSBundle mainBundle] URLForResource:@"wh_3c" withExtension:@"mp4"];
          break;
  
          case 4:
              fileURL = [[NSBundle mainBundle] URLForResource:@"wh_3d" withExtension:@"mp4"];
          break;
  
          default:
              return;
          break;
      }
  
      AVURLAsset *asset = [AVURLAsset URLAssetWithURL:fileURL options:nil];
      NSString *tracksKey = @"tracks";
  
      [asset loadValuesAsynchronouslyForKeys:[NSArray arrayWithObject:tracksKey] completionHandler:
   ^{
       // The completion block goes here.
       NSError *error = nil;
       AVKeyValueStatus status = [asset statusOfValueForKey:tracksKey error:&amp;error];
  
       if (status == AVKeyValueStatusLoaded)
       {
           self.playerItem = [AVPlayerItem playerItemWithAsset:asset];
  
           [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playerItemDidReachEnd:) name:AVPlayerItemDidPlayToEndTimeNotification object:playerItem];
  
           self.player = [AVPlayer playerWithPlayerItem:playerItem];
           [playerView setPlayer:player];
  
           [self.player seekToTime:kCMTimeZero];
  
           [self play];
       }
       else {
           // Deal with the error appropriately.
           NSLog(@"The asset's tracks were not loaded:\n%@", [error localizedDescription]);
       }
   }];
  }
  </code></pre>