原文鏈接: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;