对于iOS平台的视频播放,我们可以借助Cocos2d-iphone 的Extensions:CCVideoPlayer来实现
1.导入支持cocos2d-x的扩展库到项目中(这里可以参考Himi的第六章视频播放小节内容,这里的扩展库是Himi修改好的,我就直接拿来用了!希望没有侵权!)
2.添加MediaPalyer框架到项目中
3.修改ios里AppController.h 和AppController.mm文件
AppController.h
- #import"../Classes/CCVideoPlayeriOS/CCVideoPlayer.h"
- @classRootViewController;
- @interfaceAppController:NSObject<UIAccelerometerDelegate,UIAlertViewDelegate,
- UITextFieldDelegate,UIApplicationDelegate,CCVideoPlayerDelegate>
- {
- UIWindow*window;
- RootViewController*viewController;
- }
- @property(nonatomic,retain)UIWindow*window;
- @property(nonatomic,retain)RootViewController*viewController;
- -(void)playVideo;
- @end
AppController.mm
添加using namespace cocos2d;
因为playVideo用到了cocos2d-x里的api
CCSizesize = CCDirector::sharedDirector()->getWinSize();
[CCVideoPlayer setDelegate :self];
playVideo实现如下:
- -(void)playVideo
- {
- CCSizesize=CCDirector::sharedDirector()->getWinSize();
- [CCVideoPlayersetScrrenSize:CGSizeMake(size.width-400,size.height-300)];
- [CCVideoPlayersetNoSkip:true];
- [CCVideoPlayerplayMovieWithFile:@"xcm.mp4"];
- //播放网络视频
- //[viewControllerplayURLVideo];
- }