title: avplayer doesn't pause when clicked on pause button if screen is locked
body: <p>If the app is playing the audio and phone screen is locked then control screen is shown as below. I am not able to take any action on avplayer</p>
  
  <p><a href="https://i.stack.imgur.com/gwfma.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gwfma.png" alt="enter image description here"></a></p>
  
  <p>In my appdelegate I implemented:</p>
  
  <pre><code>- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
      MPRemoteCommandCenter *rcc = [MPRemoteCommandCenter sharedCommandCenter];
  [[rcc skipForwardCommand] setEnabled:NO];
  [[rcc skipBackwardCommand] setEnabled:NO];
  [[rcc nextTrackCommand] setEnabled:NO];
  [[rcc previousTrackCommand] setEnabled:NO];
  [[rcc skipForwardCommand] setEnabled:NO];
  [[rcc skipBackwardCommand] setEnabled:NO];
  rcc.playCommand.enabled = YES;
  rcc.pauseCommand.enabled = YES;
  [[MPRemoteCommandCenter sharedCommandCenter].playCommand addTarget:self action:@selector(play)];
  [[MPRemoteCommandCenter sharedCommandCenter].pauseCommand addTarget:self action:@selector(pause)];
  }
  
  - (void) play {
  [[MyVideoController instance] play];
  }
  
  - (void) pause {
  [[MyVideoController instance] pause];
  }
  </code></pre>
  
  <p>class MyVideoController consists of:</p>
  
  <pre><code>- (void) pause {
      [self.avPlayer pause];
  }
  
  - (void) play {
      [self.avPlayer play];
  }
  </code></pre>
  
  <p>Even though these methods are triggered (added breakpoints to check), no action on avplayer is taken. No matter what, avplayer doesn't pause.</p>
  
  <p>Is there any way to pause the avplayer?</p>
  
  <p>EDIT 1:
  Adding the complete code</p>
  
  <p>In my AppDelegate:</p>
  
  <pre><code>- (void) remoteControlReceivedWithEvent: (UIEvent *) event {
  [[ZVideoPlayerController instance] eventReceived:event];
  if (event.type == UIEventTypeRemoteControl) {
      switch (event.subtype) {
          case UIEventSubtypeRemoteControlTogglePlayPause: {
  
              break;
          }
          case UIEventSubtypeRemoteControlPlay: {
              [[ZVideoPlayerController instance] play];
              break;
          }
          case UIEventSubtypeRemoteControlPause: {
              [[ZVideoPlayerController instance] pause];
              break;
          }
          default:
              break;
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <pre><code>- (void)applicationDidEnterBackground:(UIApplication *)application {
  [[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
  [self becomeFirstResponder];
  }
  
  - (void)applicationDidBecomeActive:(UIApplication *)application {
  [[UIApplication sharedApplication] endReceivingRemoteControlEvents];
  }
  </code></pre>
  
  <p>I AM RECEIVING EVENTS BUT THE AUDIO DOESN'T PAUSE UPON CALLING PAUSE METHOD ON AVPLAYER.</p>
  
  <p>EDIT 2:
  instance declaration in PlayerController class</p>
  
  <pre><code>+ (instancetype)instance {
  static id instance = nil;
  if (instance == nil)
  {
      static dispatch_once_t onceToken = 0;
      dispatch_once(&amp;onceToken, ^(void) {
          NSAssert(instance == nil, @"Singleton instance is already allocated.");
          instance = [[super allocWithZone:NULL] init];
      });
  }
  return instance;
  }
  </code></pre>
  
  <p>initialising AVPlayer</p>
  
  <pre><code>    AVURLAsset *avAsset = [AVURLAsset URLAssetWithURL:url options:nil];
  AVPlayerItem *playerItem = [AVPlayerItem playerItemWithAsset:avAsset];
  AVAudioSession *session = [AVAudioSession sharedInstance];
  [session setCategory:AVAudioSessionCategoryPlayback error:nil];
  NSError *activationError = nil;
  BOOL success = [[AVAudioSession sharedInstance] setActive: YES error: &amp;activationError];
  
  NSMutableDictionary *songInfo = [[NSMutableDictionary alloc] init];
  
  MPMediaItemArtwork *albumArt = [[MPMediaItemArtwork alloc] initWithImage: [UIImage imageNamed:@"Audio_Thumbnail_Play"]];
  [songInfo setObject:title forKey:MPMediaItemPropertyTitle];
  [songInfo setObject:@"100" forKey:MPMediaItemPropertyPlaybackDuration];
  [songInfo setObject:albumArt forKey:MPMediaItemPropertyArtwork];
  [[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:songInfo];
  self.avPlayer = [AVPlayer playerWithPlayerItem:playerItem];
  self.avPlayerLayer = [AVPlayerLayer playerLayerWithPlayer:self.avPlayer];
  </code></pre>