解决VideoPlayer视频层级放在Cocos渲染底层

感谢大神的分享(解决VideoPlayer视频层级无法放在Cocos渲染底层问题—Android篇)
根据他的思路,我这里补充ios端相关的修改,当前修改在3.8.8版本验证可使用

第一步:

  • 开启cocos背景透明,由于我们希望在cocos下层依然显示一些东西,那么就需要把cocos背景设置为透明
  • Cocos项目设置->宏配置->开启 ENABLE_TRANSPARENT_CANVAS
  • 设置Camera组件的ClearColor颜色alpha通道为0

第二步:

  • 修改AppDelegate.mm里didFinishLaunchingWithOptions函数
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
        [[SDKWrapper shared] application:application didFinishLaunchingWithOptions:launchOptions];
        appDelegateBridge = [[AppDelegateBridge alloc] init];
        // Add the view controller's view to the window and display.
        CGRect bounds = [[UIScreen mainScreen] bounds];
        self.window   = [[UIWindow alloc] initWithFrame:bounds];

        // Should create view controller first, cc::Application will use it.
        _viewController                           = [[ViewController alloc] init];
        _viewController.view                      = [[View alloc] initWithFrame:bounds];
        _viewController.view.contentScaleFactor   = UIScreen.mainScreen.scale;
        _viewController.view.multipleTouchEnabled = true;
        _viewController.view.backgroundColor = [UIColor clearColor];
        [self.window setRootViewController:_viewController];

        [self.window makeKeyAndVisible];
        [appDelegateBridge application:application didFinishLaunchingWithOptions:launchOptions];
        return YES;
}
  • 修改VideoPlayer-ios.mm
- (void)addPlayerControllerSubView {
    auto rootView = UIApplication.sharedApplication.delegate.window.rootViewController.view;
    [rootView.superview insertSubview:self.playerController.view atIndex:0];
}

编译运行即可

4赞

mark一下

mark一下