Is there any UIVideoPlayer tutorial?

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:

#include "ui/UIVideoPlayer.h"

Example:

const cocos2d::Size visibleSize(cocos2d::Director::getInstance()->getVisibleSize());
auto videoPlayer = cocos2d::experimental::ui::VideoPlayer::create();
videoPlayer->setContentSize(visibleSize);
videoPlayer->setAnchorPoint(cocos2d::Vec2::ANCHOR_MIDDLE);
videoPlayer->setPosition(visibleSize / 2);
videoPlayer->setFileName("video.mp4");
addChild(videoPlayer);
videoPlayer->play();

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:

#ifndef __COCOS2D_UI_VIDEOWEIGTH_H_
#define __COCOS2D_UI_VIDEOWEIGTH_H_

#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS)

#include "ui/UIWidget.h"

/**
 * @addtogroup ui
 * @{
 */

NS_CC_BEGIN
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__)
#undef  CC_TARGET_PLATFORM
#define CC_TARGET_PLATFORM         CC_PLATFORM_MAC
#endif

// iphone
#if defined(CC_TARGET_OS_IPHONE)
    #undef  CC_TARGET_PLATFORM
    #define CC_TARGET_PLATFORM         CC_PLATFORM_IOS
#endif

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?