I am trying to detect when a user presses the play/pause button on the remote. I have created a tap gesture recognizer and attached it to the view of a AVPlayerViewController subclass.
UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(togglePlayPause:)];
tapGestureRecognizer.allowedPressTypes = @[@(UIPressTypePlayPause)];
[self.view addGestureRecognizer:tapGestureRecognizer];
- (void)togglePlayPause:(UITapGestureRecognizer *)tapGestureRecognizer
{
NSLog(@"Toggle play/pause");
if ([self playing])
{
NSLog(@" Pause");
[self.player pause];
}
else
{
NSLog(@" Play");
[self.player play];
}
}
The gesture fires fine when the "play" button is pressed but does not when the "pause" button is pressed. Any ideas why?