Is there any UIVideoPlayer tutorial?

Is there any UIVideoPlayer tutorial?
0.0 0

#1

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?


#2

take a look at cpp_test (UIVideoPlayerTest) :slight_smile:


#3

what Do you mean by that?


#4

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.


#5

ANyone? Please help!


#6

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();

#7

#8

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


#9

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!


#10

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.


#11
#include "ui/UIVideoPlayer.h"

#12

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


#13
#include "ui/CocosGUI.h"

#14

Same problem.


#16

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

#17

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.


#18

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


#19


#20

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.


#21

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