Recently, the video playback function was needed because of project requirements.
Before the 3.x version, if you need to use the video playback function will be using the native video playback technology, fortunately, after 3.x the official integration of video playback function, it is gratifying. But the tragedy of the relief is that the official documentation has not kept pace with the version update. Although this feature is integrated, it's frustrating that you're going to have to spend a lot of effort trying to use tricks (just like my rookie).
The following for me a long time to touch the use of methods, in fact, the use is not difficult, it is important to note that this integrated player (Videoplayer) is platform-Limited. Some code is only available on Android platforms and iOS platforms. Nonsense not much to say, directly on the instance code:
HelloWorldScene.h file
<span style= "FONT-SIZE:18PX;" > #ifndef __helloworld_scene_h__#define __helloworld_scene_h__#include "cocos2d.h"//must introduce the following 2. H file # include "ui/ UIVideoPlayer.h "#include" ui/cocosgui.h "Using_ns_cc;class helloworld:public layer{public: static scene* Createscene (); virtual BOOL init (); void OnEnter (); void Videoplayovercallback (); void Showvideo ();/** * Video playback status, only valid on Android and iOS platform */#if (Cc_target_platform = = Cc_platform _android | | Cc_target_platform = = Cc_platform_ios) void Videoeventcallback (ref* sender, Cocos2d::experimental::ui::videoplayer:: EventType eventtype); #endif Create_func (HelloWorld);}; #endif </span>
HelloWorldScene.cpp file
<span style= "FONT-SIZE:18PX;" > #include "HelloWorldScene.h" USING_NS_CC; scene* helloworld::createscene () {Auto scene = Scene::create (); Auto layer = Helloworld::create (); Scene->addchild (layer); return scene;} BOOL Helloworld::init () {if (! Layer::init ()) {return false; } return true; void Helloworld::onenter () {layer::onenter (); Showvideo ();} void Helloworld::showvideo () {Size size = Director::getinstance ()->getvisiblesize (); #if (Cc_target_platform = = CC_ platform_android | | Cc_target_platform = = Cc_platform_ios) Auto Videoplayer = Cocos2d::experimental::ui::videoplayer::create (); Videoplayer->setposition (Point (SIZE.WIDTH/2, SIZE.HEIGHT/2)); Videoplayer->setanchorpoint (Vec2::ANCHOR_ Middle); Videoplayer->setcontentsize (Size (Size.width, Size.Height)); This->addchild (Videoplayer); if ( Videoplayer) {videoplayer->setfilename ("1111.mp4"); Videoplayer->play ();} Videoplayer->addeventlistener (cc_callback_2 (helloworld::videoeventcallback, this); #endif}/** * Video playback completed callback function */void Helloworld::videoplayovercallback () {}/** * video playback status * Note The code here, This code is valid only on ANDROID platform and iOS platform */#if (Cc_target_platform = = Cc_platform_android | | Cc_target_platform = = Cc_platform_ios) void Helloworld::videoeventcallback (ref* sender, Cocos2d::experimental::ui:: Videoplayer::eventtype eventtype) {switch (eventtype) {case Cocos2d::experimental::ui::videoplayer::eventtype:: Playing:break;case cocos2d::experimental::ui::videoplayer::eventtype::P aused:break;case cocos2d::experimental:: Ui::videoplayer::eventtype::stopped:break;case cocos2d::experimental::ui::videoplayer::eventtype::completed: Videoplayovercallback (); break;default:break;}} #endif </span>
So you can achieve video playback, video control Please refer to the official demo
COCOS2DX 3.3 Video playback of the implementation of-videoplayer use