Respond to Apple TV controls while playing video

I have an application with AVPlayer to play videos. I would like to be able to detect when the user pressed a button on the remote control. I tried to implement the following methods, however remoteControlReceivedWithEvent () does not respond to any control events.

- (void)remoteControlReceivedWithEvent:(UIEvent *)event {
    //if it is a remote control event handle it correctly
    if (event.type == UIEventTypeRemoteControl) {
        if (event.subtype == UIEventSubtypeRemoteControlPlay) {
            NSLog(@"play");
        } else if (event.subtype == UIEventSubtypeRemoteControlPause) {
            NSLog(@"pause");
        } else if (event.subtype == UIEventSubtypeRemoteControlTogglePlayPause) {
            NSLog(@"toggle");
        }
    }
}

- (BOOL)canBecomeFirstResponder {
    return YES;
}

- (void)viewDidAppear:(BOOL)animated {
    // Setup Apple TV control events
    [super viewDidAppear:animated];
    [[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
    [self becomeFirstResponder];
}

- (void)viewWillDisappear:(BOOL)animated {
    // Remove Apple TV control events
    [super viewWillDisappear:animated];
    [[UIApplication sharedApplication] endReceivingRemoteControlEvents];
    [self resignFirstResponder];
}

Any help would be appreciated, thanks!

+4
source share
3 answers

This seems to be a problem with projects built using the Xcode 7 / iOS 9 SDK. Tried the same thing using Xcode 6, works great. I picked it up with an Apple reporter.

0
source

, , , , .

AVPlayer KVO "rate". 0.0, , 1.0, .

, , .

0

UITapGestureRecognizer tvOS. allowedPressType (, @[@(UIPressTypePlayPause)]).

tvOS. AVPlayerViewController (AVKit). ( Siri , , ..).

, AVPlayerViewController , - API- tvOS , .

-1

Source: https://habr.com/ru/post/1606338/


All Articles