title: AVPlayer play video in background
body: <p>I am using AVPlayer to play a video in my app,now i want to let the video play in background mode.</p>
  
  <p>this is what i put in the <code>- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions</code>:</p>
  
  <pre><code>[[AVAudioSession sharedInstance] setDelegate: self];    
  [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
  </code></pre>
  
  <p>and i also add to the plist:
  Required background modes -> App plays audio</p>
  
  <p>I add this too:</p>
  
  <pre><code>-(void)viewDidAppear:(BOOL)animated{
      [super viewDidAppear:animated];
      [[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
      [self becomeFirstResponder];
  }
  
  - (BOOL)canBecomeFirstResponder {
      return YES;
  }
  
  - (void)remoteControlReceivedWithEvent:(UIEvent *)event {
      switch (event.subtype) {
          case UIEventSubtypeRemoteControlTogglePlayPause:
              NSLog(@"4");
              break;
          case UIEventSubtypeRemoteControlPlay:
              break;
          case UIEventSubtypeRemoteControlPause:
              NSLog(@"3");
              break;
          case UIEventSubtypeRemoteControlNextTrack:
              NSLog(@"2");
              break;
          case UIEventSubtypeRemoteControlPreviousTrack:
              NSLog(@"1");
              break;
          default:
              break;
      }
  }
  </code></pre>
  
  <p>And when i move the app to the background and press the buttons the nslog print to the console</p>
  
  <p>Did i need to add something else?</p>