For an iOS only project I built in Cocos v.2.2 I implemented video playback, and now that v.3.2 has experimental VideoPlayer, I thought I’d give it a quick look to see if it will meet my needs, and at this point is does not.
I use videos as an app intro or transitions between scene, thus I do not want the user to be able to directly interact with the video player, and only affect it through any UI I provide, like in the case of an intro video I want to add a “skip” button on top of (z not y) the video.
To get this to work, in my implementation, I put the video player behind the OpenGL view. It looks like the experimental VideoPlayer sits on top of the OpenGL layer, which means that it is not possible to have UI on top of the player.
To accomplish this, I did the following. In AppController.mm, instead of:
_viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil];
_viewController.wantsFullScreenLayout = YES;
_viewController.view = eaglView;
I have:
_viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil];
_viewController.wantsFullScreenLayout = YES;
eaglView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin |
UIViewAutoresizingFlexibleRightMargin |
UIViewAutoresizingFlexibleTopMargin |
UIViewAutoresizingFlexibleBottomMargin |
UIViewAutoresizingFlexibleWidth |
UIViewAutoresizingFlexibleHeight;
_viewController.view.autoresizesSubviews = YES;
_viewController.view.frame = eaglView.frame;
[_viewController.view addSubview:eaglView];
_viewController.view.backgroundColor = [UIColor clearColor];
eaglView.backgroundColor = [UIColor clearColor];
Thus making the GLView a subview of the rootViewController, not it’s main view. Then, when adding the player to the view, instead of (UIVideoPlayerIOS.mm):
[eaglview addSubview:self.moviePlayer.view];
I have:
[[eaglview superview] insertSubview:self.moviePlayer.view atIndex:0];
glClearColor(0, 0, 0, 0); // required to see the video behind the GLView
Thus inserting the videoplayer view behind the GLView, so the GLView can supply the UI. Additionally, I change controlStyle to none:
self.moviePlayer.controlStyle = MPMovieControlStyleNone;
I have no idea how to do this on the Android side, or if it is even possible, but I would love to see these integrated in for v3.3. If nothing else, these changes can be used by other developers who want to produce the same results as I wanted.