Is there any UIVideoPlayer tutorial?

Is there any UIVideoPlayer tutorial?
0.0 0


I could not find any guide or tutorial to use UIVideoPlayer in cocos2dx.

I want to play some mp4 video files enabling video player controls such as play/pause, progress bar, Rew/Fwd.

I assuming UIVideoPlayer is the way to go.

any tips?


take a look at cpp_test (UIVideoPlayerTest) :slight_smile:


what Do you mean by that?


I tried it for cocos2d 3.7 and when I add line: using namespace cocos2d::experimental::ui; is said that there is no such namespace. Is there a simple sample of playing video using cocos2d 3.7 or 3.8 ? I need it can be played on iOS and adnroid.


ANyone? Please help!



#include "ui/UIVideoPlayer.h"


const cocos2d::Size visibleSize(cocos2d::Director::getInstance()->getVisibleSize());
auto videoPlayer = cocos2d::experimental::ui::VideoPlayer::create();
videoPlayer->setPosition(visibleSize / 2);



Can you please share working project for Xcode? Thank you in advance.


The tests work excellently in Xcode. For example:

I think your best option is to start with an empty project and then add either code from the test above or from my example above. Good luck!


No, it’s not. As you see in my prev. post…

Also when I just add:

using namespace cocos2d::ui;
using namespace cocos2d::experimental::ui;

I got an error, that - cocos2d::experimental::ui; not found.

#include "ui/UIVideoPlayer.h"


Yes, I did this. But anyway I got this problem.

#include "ui/CocosGUI.h"


Same problem.


Check your platform preprocessor settings, as the headers have guards in place:



#include "ui/UIWidget.h"

 * @addtogroup ui
 * @{

namespace experimental{
    namespace ui{

Make sure your Xcode pre-processror definition is set to CC_TARGET_OS_IPHONE, not CC_TARGET_OS_MAC or _APPLE_:

// mac
#if defined(CC_TARGET_OS_MAC) || defined(__APPLE__)

// iphone
#if defined(CC_TARGET_OS_IPHONE)


If I create a new project (“cocos new …”), open it and enter the following in HelloWorldScene.cpp:

#include "ui/UIVideoPlayer.h"

using namespace cocos2d::ui;
using namespace cocos2d::experimental::ui;

…it compiles perfectly.

Did you try that?

I am using cocos2d-x 3.8.1 and Xcode 7.0.


Yes, and it works. But my project was created a long time ago and when I got this errors now.



Break into the ui/UIVideoPlayer.h header file and check the code path and settings of the defines, to make sure it’s executing the experimental namespace codepath.


Sorry, my english not so good, what do you mean by this?