I created an AVPlayerViewController
and an attached AVPlayer
in the viewDidAppear
method of a custom UIViewController
. Ho
One way is to add additional action to the existing "Done" button on the AVPlayerViewController by searching the respective UIButton inside the subviews of AVPlayerViewController. Once the button is found, add a custom action using addTarget:action:forControlEvents:
At least this works for me.
- (UIButton*)findButtonOnView:(UIView*)view withText:(NSString*)text
{
__block UIButton *retButton = nil;
[view.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
if([obj isKindOfClass:[UIButton class]]) {
UIButton *button = (UIButton*)obj;
if([button.titleLabel.text isEqualToString:text]) {
retButton = button;
*stop = YES;
}
}
else if([obj isKindOfClass:[UIView class]]) {
retButton = [self findButtonOnView:obj withText:text];
if(retButton) {
*stop = YES;
}
}
}];
return retButton;
}
- (void)showPlayer:(AVPlayer*)player
{
AVPlayerViewController *vc = [[AVPlayerViewController alloc] init];
vc.player = player;
[self presentViewController:vc animated:NO completion:^{
UIButton *doneButton = [self findButtonOnView:vc.view withText:@"Done"];
[doneButton addTarget:self action:@selector(doneAction:) forControlEvents:UIControlEventTouchUpInside];
[vc.player play];
}];
}
- (void)doneAction:(UIButton*)button
{
// perform any action required here
}