AVPlayerViewController with custom overlay

江枫思渺然 提交于 2019-12-11 13:22:39

问题


Migrating to AVkit from MPMoviePlayer has brought me to a blocking issue.

I need to display a custom tableView over the AVPlayerViewController. I can this tableview trough

[self.avVideoPlayer.contentOverlayView addsubiew:self.mycustomTableView]

and it is visible but it doesn't receive any tap/swipe events.

Any ideas why this happens or how can I add the table view in a place where it would receive the touch events even in the fullscreen mode?


回答1:


[self.view addSubview:btn];

This will add the button in the minimised player.

Now for the fullscreen scenario you need to add an observer for the videoBounds, here is my code:

   [self.avVideoPlayer addObserver:self forKeyPath:@"videoBounds" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld context:NULL];

Now here comes the not so pretty part:

- (void)observeValueForKeyPath: (NSString*) path
                  ofObject: (id)object
                    change: (NSDictionary*)change
                   context: (void*)context {

NSLog(@"SOME OBSERVER DID THIS: %@ , %@",object,change);
if ([self playerIsFullscreen]) {
    for(UIWindow* tempWindow in [[UIApplication sharedApplication]windows]){
        for(UIView* tempView in [tempWindow subviews]){

            if ([[tempView description] rangeOfString:@"UIInputSetContainerView"].location != NSNotFound){
                UIButton *testB = [[UIButton alloc] initWithFrame: CGRectMake(20, 20, 400, 400)];
                testB.backgroundColor = [UIColor redColor];
                [testB addTarget:self action:@selector(buttonTouch) forControlEvents:UIControlEventTouchDown];
                [tempView addSubview:testB];

                break;
            }
        }
    }
}
}

I know this is a not a nice way to do it, but it is the only way I managed to add some custom UI that also receives touch events on the player.

Cheers!



来源:https://stackoverflow.com/questions/27252187/avplayerviewcontroller-with-custom-overlay

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!