(ios)使用视频(MP4)当做背景(如keep登录页)

最新教程和源码请访问公众号

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

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值