title: Resume AVPlayer video playback after app become active
body: <p>I write custom player from AVPlayer for video playback. According to Apple docs set the video layer: </p>
  
  <pre><code>    self.player = [IPLPlayer new];
      self.player.playerLayer = (AVPlayerLayer *)self.playerView.layer;
  </code></pre>
  
  <p>Where self.playerView is usual class from those docs: </p>
  
  <pre><code>    @implementation PlayerView
  
  + (Class) layerClass {
      return [AVPlayerLayer class];
  }
  
  - (AVPlayer *)player {
      return [(AVPlayerLayer *)[self layer] player];
  }
  
  - (void)setPlayer:(AVPlayer *) player {
      [(AVPlayerLayer *) [self layer] setPlayer:player];
  }
  </code></pre>
  
  <p>The problem is:
  When close app (Home button), or block screen, the video playback is stopped, and when resume ONLY audio playback resumed, the image on screen is still those was before block screen - it's fully static and note change frames.</p>
  
  <p><strong>How to resume VIDEO playing after screen is blocked?</strong></p>
  
  <p>Seems I must to register notifications, and after app become active resume video layer:</p>
  
  <pre><code>    -(void)registerNotification
  {
      [[NSNotificationCenter defaultCenter] addObserver:self
                                               selector:@selector(willEnterBackground)
                                                   name:UIApplicationWillResignActiveNotification object:nil];
      [[NSNotificationCenter defaultCenter] addObserver:self
                                               selector:@selector(didEnterForeground)
                                                   name:UIApplicationDidBecomeActiveNotification object:nil];
  }
  
  -(void)unregisterNotification
  {
      [[NSNotificationCenter defaultCenter] removeObserver:self];
  }
  
  
  -(void)willEnterBackground
  {
      NSLog(@"willEnterBackground");
      [self.playerView willEnterBackground];
  }
  
  -(void)didEnterForeground
  {
      NSLog(@"didEnterForeground");
      [self.playerView didEnterForeground];
  }
  </code></pre>