原文地址:http:///www.cocos2d-x.org/boards/7/topics/550

Got this working, thought I'd share:

Can also be found on my not very often updated blog hereOK, first thing you need to know is that Cocos2d doesn’t play videos, it leaves this up to the iOS SDK on the devices. The following code therefore is Obj C which can be inserted into your projects AppController.mm file or you could create a new mm interface file and put it in there.Add the “AVFoundation.framework” to your projects Frameworks (located the Frameworks folder, right click, select “Add -> Existing Frameworks”).
Add the “MediaPlayer.framework” to your projects Frameworks.
You will need a video to play and to add it to the resources in the project. Use your own or download my sample video from here
Add the following code to your AppController.mm
////

MPMoviePlayerViewController *playerViewController=NULL;
int g_iPlayVideoState=0;- (void)PlayVideo:(int)iStateAfterPlay fullscreen:(int)iFullScreen file:(NSString*)strFilennameNoExtension fileExtension:(NSString*)strExtension
{NSLog(@"PlayVideo start");g_iPlayVideoState = 2;NSString *url = [[NSBundle mainBundle] pathForResource:strFilennameNoExtension ofType:strExtension];CGRect rScreen;rScreen.origin.x = 0;rScreen.origin.y = 0;rScreen.size.width = 480;rScreen.size.height = 320;//rScreen = CGRect::CGRectMake(0,0, 480, 320);        if( iFullScreen==0 ){MPMoviePlayerController *player2 = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:url]];[[NSNotificationCenter defaultCenter] addObserver:selfselector:@selector(movieFinishedCallback:)name:MPMoviePlayerPlaybackDidFinishNotificationobject:player2];//---play partial screen---player2.view.frame = rScreen;[self addSubview:player2.view];player2.shouldAutoplay=TRUE;//---play movie---
        [player2 play];}   else{playerViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL fileURLWithPath:url]];[[NSNotificationCenter defaultCenter] addObserver:selfselector:@selector(movieFinishedCallback:)name:MPMoviePlayerPlaybackDidFinishNotificationobject:[playerViewController moviePlayer]];playerViewController.view.frame = rScreen;cocos2d::CCDirector::sharedDirector()->purgeCachedData();// Add the viewEAGLView *view = [EAGLView sharedEGLView];[view addSubview:playerViewController.view];[view sendSubviewToBack:view];NSLog(@"pView inserted");// Add the view - Use these three lines for Cocos 2D Xwindow = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]];[window addSubview: playerViewController.view];[window makeKeyAndVisible];//---play movie---MPMoviePlayerController *player = [playerViewController moviePlayer];player.scalingMode=MPMovieScalingModeAspectFit;player.shouldAutoplay=TRUE;[player play];}g_iPlayVideoState = 1;NSLog(@"PlayVideo done");
}////
- (void) movieFinishedCallback:(NSNotification*) aNotification
{NSLog(@"movieFinishedCallback");MPMoviePlayerController *player = [aNotification object];[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:player];    [player.view removeFromSuperview];[player autorelease];    g_iPlayVideoState = 0;NSLog(@"movieFinishedCallback done");
}Call the PlayVideo function from with a line like the following. Call it from your AppController’s didFinishLaunchingWithOptions function just before (or after) the app.run();[self PlayVideo:0 fullscreen:1 file:@"ThreeSheets_Title_480x272" fileExtension:@"m4v"];
In Appelegate.cpp, find your applicationDidFinishLaunching() function and after “pDirector->setOpenGLView(m_pMainWnd);” add the line:glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
The above gl command sets your Cocos2D-X window to transparent wherever it is black, so you can see through it to the video behind.I have a global variable “g_iPlayVideoState” which you can monitor in your Cocos2D applications code to detect when the video ends, its values are 2=initializing, 1=playing, 0=finished. At the end of play you might want to put the views back to non-transparent with the call “glClearColor(0.0f, 0.0f, 0.0f, 1.0f);

Playing Video on iPhone Cocos2D-X相关推荐

  1. video在iPhone浏览器上播放没有声音

    <audio :src=msurl loop autoplay id="MusicPlay"></audio>......var media = docum ...

  2. 【综述翻译】Deep Learning for Video Game Playing

    深度强化学习实验室 原文来源:https://arxiv.org/pdf/1708.07902.pdf 翻译作者:梁天新博士 编辑:DeepRL 在本文中,我们将回顾最近的Deep Learning在 ...

  3. iPhone 开发中心 论坛 与 视频

    苹果开发者联盟 - iPhone 开发中心  http://www.apple.com.cn/developer/iphone/  http://developer.apple.com/devcent ...

  4. unity3d iPhone文件目录介绍

    原地址:http://cl314413.blog.163.com/blog/static/190507976201210259126559/ 如何查看iPhone文件存放目录?首先需要越狱,越狱后打开 ...

  5. H5 video 开发问题及相关知识点

    相关链接: H5 video 的使用 H5 video 全屏播放 ♢ video点播与直播  H5 video目前所有浏览器都支持的视频格式是MP4格式,所以mp4应当是点播web视频的首选格式. 而 ...

  6. 如何禁止 iPhone Safari 视频自动全屏?

    <video id="post" autoplay loop preload="auto"> <source src="foo.mp ...

  7. html video标签canplay,HTML oncanplay事件用法及代码示例

    当指定的音频/视频缓冲到足以开始时,就会发生HTML DOM oncanplay事件. 事件的发生顺序在音频/视频的加载过程中: onloadstart ondurationchange onload ...

  8. mac上将视频变小_如何在Linux上将iPhone的.mov视频旋转90度?

    mac上将视频变小 The video files copied from iPhone is rotated by 90 degree when they are played on Linux. ...

  9. .net程序员的iPhone开发-MonoTouch

      iPhone软件的Native开发除了使用Apple推荐的Objective-C  Cocoa之外,也有其他的一些工具和SDK提供 基于WEB的形式的一些框架在下面这个文章介绍过 各种SmartP ...

最新文章

  1. python mysql 帮助类
  2. RPA女子计划—面向日本女性的工作方式改革
  3. 批处理 正则表达式(findstr) 整理
  4. 使用二维码识别技术的好处_人脸识别技术什么场景都能使用吗?
  5. 史上最烂代码_历史上最大的代码库
  6. 交换机设备登录账号权限1_计算机网络管理员考试试题和答案
  7. 张朝阳:搜狐Q3广告业务稳健游戏业务超预期 有望全年实现盈利
  8. 【Clickhouse】Clickhouse Cannot create table with column ‘Int256‘ because experimental bigint types
  9. 零基础轻松学python pdf 小码哥_零基础轻松学Python
  10. Android平台下基于XMPP的IM研究
  11. Kafka的安装部署(分布式部署安装)
  12. Gulp解决发布线上文件(CSS和JS)缓存问题
  13. Guava学习笔记 第6个记录(Immutable(不可变)集合)
  14. canape数据导入matlab,CANape使用介绍
  15. fast rcnn和faster rcnn
  16. 7-4 哈夫曼编码 (30分)
  17. 1012: 求绝对值 C语言
  18. 转录组分析之 Trimming对reads进行处理
  19. ubuntu ffmpeg 截取视频指定时间范围,坐标范围
  20. 我的苹果电脑中毒了?mac也会中病毒?喜闻乐见(附杀毒软件测试)

热门文章

  1. 低版本不能使用php 命令,创建软链接
  2. bzoj 1095: [ZJOI2007]Hide 捉迷藏
  3. SQL Server 备份还原造成孤立用户的问题
  4. 给url添加时间戳,解决浏览器缓存
  5. 在mac操作系统下,Intellij IDEA默认jdk版本的修改
  6. 数据挖掘原理与算法:对森林火灾影响因素的分析
  7. 用计算机源码计算加法,MFC实现简单计算器(支持加减乘除和括号运算)
  8. 微型计算机2013年10月下,微型计算机及接口技术2013年10月真题试题(04732)
  9. js map遍历 修改对象里面的值_求职季之你必须要懂的原生JS(上)
  10. 星型模型 3nf的区别_贵州省遵义市工业模型经典案例展示