tvOS Play/Pause Gesture

Hi Everyone,


I've been having some trouble with the Play/Pause button gesture recognizer.


The issue is after playing a video clip, the rest of the app cannot detect the Play/Pause button at all. It works fine before starting playback of a video using AVPlayerViewController but after watching a video it is not recognizable in any other View Controller.


I have tried reassigning the gesture recognizer when coming back to a View Controller, but that doesn't help either.


var tapRecognizer = UITapGestureRecognizer(target: self, action: "playButtonPressed:")

tapRecognizer.allowedPressTypes = [NSNumber(integer: UIPressType.PlayPause.rawValue)];

self.view.addGestureRecognizer(tapRecognizer)


I also tried using the pressesBegan & pressesEnded methods as well and found the same issue.


Has anyone else experience this problem?


I would really like to use the Play/Pause button throughout the app, since it's the only remote button available other than menu.


Thanks!

Brian

Replies

I just posted here about something similar. All I know is that AVPlayerViewController is $%^& futzy about letting you use controls in any way not originally intended. Pause (rate == 0.0) seems to always bring up the shuttle. My theory is that the shuttle is in it's own overlay view, and gestureRecognizers do not participabe in responder propagation. If I'm right, considering that there is no acceess to the video control view (at least tha I've found), there is no way to attach a gestureRecognizer to it.

Hey Applegg,


Thanks for your reply.


I don't need to add a gestureRecognizer to the AVPlayerViewController. The Play/Pause button should act as they should (video controls) within the AVPlayerViewController.


The issue I am having is after I play any video in an AVPlayerViewController, and leave that view controller, I can't get any response in any gestureRecognizer I set on any other View Controller within the app. All works well before starting a AVPlayerViewController, but not after.


Brian

So you are returning to the previous view? How about preferredFocusView?


Actually, how about instead of a gesture recognizer:


override func pressesEnded(presses: Set<UIPress>, withEvent event: UIPressesEvent?) {

for press in presses {

if press.type == .PlayPause {

// whatever

}

else {

super.pressesEnded(presses, withEvent: event)

}

}

}

The previous view and any view within my app after leaving the AVPlayerViewController.


Yes I have tried pressesBegan & pressesEnded as well, no luck.


My use case is.

1. Visit a Product Detail screen.

2. Press Play/Pause to favourite a product (play/pause button works)

3. Select to play the Product video

4. Press Play/Pause to unfavourite a product (play/pause button does not work) in this View Controller or any other VC in the entire app.


I may need to file a radar.

Hi Brian,


I had the same problem a week ago. In my case, after an hour or two of logging, bug hunting, and a jolly retain cycle witch hunt, I finally tested it on actual tvOS hardware and it worked just fine. In other words, I'm pretty sure it's a simulator bug. Have you tested on hardware?

Same problem, but the other way around. Simulator works fine, bug appears on every real device...

Hi Brian,


I'm having pretty much the same exact problem...only on the hardware device, simulator works fine. Were you able to get a resolution for your problem? If you did...I'd love to hear about what you did to solve it! If not, did you file a radar bug? I'm contemplating the same...

Almost the exact same problem here, as brianfromtoronto originally described below. Hardware only, works fine in simulator. The difference for me is that I am able to hit the play button once successfully, so long as the my inline video (which used to be full-screen) is paused. Play press is detected, inline video plays. But after that, all play/pause press attempts are completed ignored.


"The issue is after playing a video clip, the rest of the app cannot detect the Play/Pause button at all. It works fine before starting playback of a video using AVPlayerViewController but after watching a video it is not recognizable in any other View Controller."

I'm having the same problem.


Did you find a solution?

Similarly digging into this issue now. I'm encountering this issue with:

  1. Adding the AVPlayerViewController as a child view controller and checking for events on the parent VC.
  2. Adding AVPlayerViewController as a child view controller, explicitly setting focus to another child view and checking for events here.
  3. Naughtily subclassing AVPlayerViewController, drawing on an AVPlayerLayer and testing for events in the subclass.

And I'm still coming up short. Hopefully there's a solution out there... (not least because I have a working demo doing much the same thing).


Edit:

`sendEvent` in `UIWindow` isn't being called for a PlayPause event, whereas it is for a Select event.

I've fixed this now by additionally implementing support for the remote control. I'm not really clear why the play/pause button reports as a remote control event or UIPress event in different circumstances, but supporting them all seems to be the way to go.


-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
   
    [[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
    [self becomeFirstResponder];
}

- (void)remoteControlReceivedWithEvent:(UIEvent *)event {
    if (shouldHandleRemote) {
        [self togglePlayPause];
    } else {
        [super remoteControlReceivedWithEvent:event];
    }
}

Hi, did you file a bug report or find another solution? In my casa I have a ViewController playing a video in AVPlayerLayer, when I click a in a button, a new ViewController is displayed with an embedded AVPlayerViewController. Play/pause button only works for the first time and the video is paused. After that play/pause button doesn't work anymore.


This problem only happens on tvos device. In simulator, this problem doesn't happen.

did you find a solution ?

since tvOS 11 usingpressesBegan/pressesEnded, GCController or gesture recognizer

doen't work anymore...

Try setting showsPlaybackControls to false when you are done with the AVPlayerViewController, that worked for me.

Thanks this worked for me!