cocos2dx 如何视频播放mp4

cocos2dx 如何视频播放mp4,第1张

cocos2d有一个扩展库“ Cocos2D-iPhone-Extensions”,Cocos2D-iPhone-Extensions中除了支持cocos2d的视频播放还附带其他的支持。

步骤一: 将下载后的Cocos2D-iPhone-Extensions包解压,然后找到Extensions/CCVideoPlayer文件夹,将CCVideoPlayer下的iOS包与“CCVideoPlayer.h”和"CCVideoPlayer.m"导入我们的项目中

步骤二:添加ios sdk中的MediaPlayer框架(真机调试程序可略过此步)

步骤三:修改需要播放视频的layer类,这里拿HelloWorldLayer举例;

在”HelloWorldLayer.h"类中,导入#import "CCVideoPlayer.h",然后让HelloWorldLayer使用协议<CCVideoPlayerDelegate>

在“HelloWorldLayer.m”类中,在init方法中添加初始化vedeoPlayer的方法:[CCVideoPlayer setDelegate: self]

然后在“HelloWorldLayer.m”类中重写如下函数:

- (void) moviePlaybackFinished

{

CCLOG(@"moviePlaybackFinished")

}

- (void) movieStartsPlaying

{

CCLOG(@"movieStartsPlaying")

}

#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED

// Updates orientation of CCVideoPlayer. Called from SharedSources/RootViewController.m

- (void) updateOrientationWithOrientation: (UIDeviceOrientation) newOrientation

{

CCLOG(@"updateOrientationWithOrientation")

[CCVideoPlayer updateOrientationWithOrientation:newOrientation ]

}

#endif

到此添加的就完成了,但是如果此时你编译会发现有一处错误,就是在扩展库的”CCVideoPlayer.m”类中还要将下面这句注视掉:#import "CCVideoPlayerImplMac.h"

OK,下面给出简单的两个常用的播放视频的方法:

[CCVideoPlayer playMovieWithFile: @"himi.mp4"]//播放视频

[CCVideoPlayer setNoSkip: YES]//视频是否可以跳过

详细请看博文:http://blog.csdn.net/xiaominghimi/article/details/6870259,谢谢!

你那个第一次创建的m_pStart是基于基本的Layer创建的,你release后但是还存在于scene中,所以,你如果想替换另外一个layer,还不需要前面的。那么你需要remove掉,比如,你添加时写一个标记tag:scene->addChild(m_pStart,tag,2)然后下面要替换另外一个你需要scene->removeChildByTag(tag),把你前面的m_pStart删掉,再添加~


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/bake/11814571.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-18
下一篇 2023-05-18

发表评论

登录后才能评论

评论列表(0条)

保存