0

I have a live video in my AVPlayerViewController and i want to disable the play pause button. How can I do that?

I tried this, but it doesn't work:

UITapGestureRecognizer *playPauseRec = [[UITapGestureRecognizer alloc] initWithTarget:self action:nil];  
playPauseRec.allowedPressTypes = @[@(UIPressTypePlayPause)];
[self.avPlayerViewController.view addGestureRecognizer:playPauseRec ];

The AVPlayerViewController is a child view controller of a View Controller.

Daniel Storm
  • 18,301
  • 9
  • 84
  • 152
CarlosAndres
  • 585
  • 1
  • 5
  • 14

3 Answers3

1

Call a different method on action of that button. I have done that by calling nothing on Action of Gesture. Here is my code

UITapGestureRecognizer *tapGestureRec = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(PlayPause)];
tapGestureRec.allowedPressTypes = @[@(UIPressTypePlayPause)];
[self.view addGestureRecognizer:tapGestureRec];   

and in playPause Function

-(void)PlayPause
  {
 NSLog(@"Do Anything or Nothing");
 }
1

If you want to disable all events (play/pause/seek) you can do this by setting the isUserInteractionEnabled flag of your AVPlayerViewController to false.

    let playerViewController = AVPlayerViewController()
    // ... setup playerViewController here

    // disable userinteraction - so no play/pause/seek events are triggered anymore
    playerViewController.view.isUserInteractionEnabled = false
Jochen Holzer
  • 1,598
  • 19
  • 25
1

If you are willing to use private APIs and want a little bit more control you can set a private delegate on AVPlayerViewController. The delegate provides some special callbacks which among other things allow you to disable pause completely.

@objc protocol YourPrivateAVPlayerViewControllerDelegate {
  @objc optional func playerViewController(_ controller: AVPlayerViewController, shouldPlayFromTime: TimeInterval, completion: @escaping (Bool) -> Void)
  @objc optional func playerViewController(_ controller: AVPlayerViewController, shouldPauseWithCompletion: @escaping (Bool) -> Void)
}

You could implement the second delegate method and call shouldPauseWithCompletion(false) to disable pause. If you want to disable pause depending on the type of stream or some other properties you could do that as well of course.

Set the delegate implementation on the AVPlayerViewController with:

playerController.perform(Selector(("setPrivateDelegate:")), with: self)
djuxen
  • 11
  • 2