最新教程和源码请访问公众号
原文链接:http://www.cocoachina.com/bbs/read.php?tid=290869&page=1&toread=1#tpc
http://m.blog.csdn.net/article/details?id=51337577
1:由于目测videoplayer控件是ios原生的uiview控件,跟cocos的绘图方式不是一个级别,所以videoplayer在添加的时候根本就没有添加到cocos的图层里,而是在图层上面新加了一个uiview控件;
解决方法呢,在appController.mm文件里先把_viewController设置成透明:
_viewController.view.backgroundColor = [UIColor clearColor];
2:然后创建一个新的uiviewcontroller来放置videoplayer的视图和cocos自己的图层,先添加video层,后加cocos层,以便cocos层把video层盖住:
appController.h里:
@property
(
nonatomic
,
readonly
) UIView* videoView;
appController.mm里:
// Use RootViewController manage CCEAGLView
_viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil];
_viewController.wantsFullScreenLayout = YES;
_viewController.view = eaglView;
//添加代码开始
_viewController.view.backgroundColor = [UIColor clearColor];
_viewController.view.tag = 3;
UIViewController* uiVC = [[UIViewController alloc] initWithNibName:nil bundle:nil];
uiVC.view.frame = [UIScreen mainScreen].bounds;
_videoView = [[UIView alloc] initWithFrame: [[UIScreen mainScreen] bounds]];
_videoView.tag = 1; //设置tag以便之后把Video层取出来~
[uiVC.view addSubview:_videoView];
[uiVC.view addSubview:_viewController.view];
// Set RootViewController to window
if ( [[UIDevice currentDevice].systemVersion floatValue] < 6.0)
{
// warning: addSubView doesn't work on iOS6
[window addSubview: uiVC.view];
}
else
{
// use this method on ios6
[window setRootViewController:uiVC];
}
//添加代码结束
[window makeKeyAndVisible];
3:接下来就可以打开UIVideoPlayer-ios.mm文件了,找到文件中
[eaglview addSubview:
self
.moviePlayer.view];
这一句,改成
[[eaglview.superview viewWithTag:1] addSubview:
self
.moviePlayer.view];
//在eaglview的父视图里找到tag=1的子视图,也就是实现设置好的Video视图。
4:在AppDelegate.cpp中添加
Director::getInstance()->setClearColor(Color4F(0, 0, 0, 0));
5:视频去掉进度条,屏蔽用户操作等:
在ios版本里视频会有一个操作栏,这个oc代码里的视频控件有个样式,更改controlStyle 这个属性,即可隐藏进度条,另外修改userInteractionEnabled 属性,让视频不响应点击事件。
在UIVideoPlayer-ios.mm中
self.moviePlayer.allowsAirPlay = false;
self.moviePlayer.controlStyle = MPMovieControlStyleNone;// MPMovieControlStyleEmbedded;
self.moviePlayer.view.userInteractionEnabled = false; //true;