mirror of https://github.com/axmolengine/axmol.git
issue #4876:Add test case to play video
This commit is contained in:
parent
af26fb9b07
commit
972f9447dd
|
@ -98,6 +98,7 @@ Classes/UITest/CocoStudioGUITest/UITextAtlasTest/UITextAtlasTest_Editor.cpp \
|
||||||
Classes/UITest/CocoStudioGUITest/UITextBMFontTest/UITextBMFontTest_Editor.cpp \
|
Classes/UITest/CocoStudioGUITest/UITextBMFontTest/UITextBMFontTest_Editor.cpp \
|
||||||
Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp \
|
Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp \
|
||||||
Classes/UITest/CocoStudioGUITest/UIWidgetAddNodeTest/UIWidgetAddNodeTest_Editor.cpp \
|
Classes/UITest/CocoStudioGUITest/UIWidgetAddNodeTest/UIWidgetAddNodeTest_Editor.cpp \
|
||||||
|
Classes/UITest/CocoStudioGUITest/UIVideoWidgetTest/UIVideoWidgetTest.cpp \
|
||||||
Classes/UITest/CocoStudioGUITest/CustomWidget/CustomImageView.cpp \
|
Classes/UITest/CocoStudioGUITest/CustomWidget/CustomImageView.cpp \
|
||||||
Classes/UITest/CocoStudioGUITest/CustomWidget/CustomImageViewReader.cpp \
|
Classes/UITest/CocoStudioGUITest/CustomWidget/CustomImageViewReader.cpp \
|
||||||
Classes/UITest/CocoStudioGUITest/CustomWidget/CustomParticleWidget.cpp \
|
Classes/UITest/CocoStudioGUITest/CustomWidget/CustomParticleWidget.cpp \
|
||||||
|
|
|
@ -279,7 +279,20 @@ g_guisTests[] =
|
||||||
Director::getInstance()->replaceScene(pScene);
|
Director::getInstance()->replaceScene(pScene);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
||||||
|
{
|
||||||
|
"gui VideoWidgetTest",
|
||||||
|
[](Ref* sender)
|
||||||
|
{
|
||||||
|
UISceneManager* pManager = UISceneManager::sharedUISceneManager();
|
||||||
|
pManager->setCurrentUISceneId(kUIVideoWidgetTest);
|
||||||
|
pManager->setMinUISceneId(kUIVideoWidgetTest);
|
||||||
|
pManager->setMaxUISceneId(kUIVideoWidgetTest);
|
||||||
|
Scene* pScene = pManager->currentUIScene();
|
||||||
|
Director::getInstance()->replaceScene(pScene);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
static const int g_maxTests = sizeof(g_guisTests) / sizeof(g_guisTests[0]);
|
static const int g_maxTests = sizeof(g_guisTests) / sizeof(g_guisTests[0]);
|
||||||
|
|
|
@ -18,6 +18,9 @@
|
||||||
#include "UIWidgetAddNodeTest/UIWidgetAddNodeTest.h"
|
#include "UIWidgetAddNodeTest/UIWidgetAddNodeTest.h"
|
||||||
#include "UIRichTextTest/UIRichTextTest.h"
|
#include "UIRichTextTest/UIRichTextTest.h"
|
||||||
#include "UIFocusTest/UIFocusTest.h"
|
#include "UIFocusTest/UIFocusTest.h"
|
||||||
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
||||||
|
#include "UIVideoWidgetTest/UIVideoWidgetTest.h"
|
||||||
|
#endif
|
||||||
/*
|
/*
|
||||||
#include "UISwitchTest/UISwitchTest.h"
|
#include "UISwitchTest/UISwitchTest.h"
|
||||||
*/
|
*/
|
||||||
|
@ -114,7 +117,10 @@ static const char* s_testArray[] =
|
||||||
"UIFocusTest-VBox",
|
"UIFocusTest-VBox",
|
||||||
"UIFocusTest-NestedLayout1",
|
"UIFocusTest-NestedLayout1",
|
||||||
"UIFocusTest-NestedLayout2",
|
"UIFocusTest-NestedLayout2",
|
||||||
"UIFocusTest-NestedLayout3"
|
"UIFocusTest-NestedLayout3",
|
||||||
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
||||||
|
"UIVideoWidgetTest"
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
static UISceneManager *sharedInstance = NULL;
|
static UISceneManager *sharedInstance = NULL;
|
||||||
|
@ -375,7 +381,10 @@ Scene *UISceneManager::currentUIScene()
|
||||||
return UIFocusTestNestedLayout2::sceneWithTitle(s_testArray[_currentUISceneId]);
|
return UIFocusTestNestedLayout2::sceneWithTitle(s_testArray[_currentUISceneId]);
|
||||||
case KUIFocusTest_NestedLayout3:
|
case KUIFocusTest_NestedLayout3:
|
||||||
return UIFocusTestNestedLayout3::sceneWithTitle(s_testArray[_currentUISceneId]);
|
return UIFocusTestNestedLayout3::sceneWithTitle(s_testArray[_currentUISceneId]);
|
||||||
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
||||||
|
case kUIVideoWidgetTest:
|
||||||
|
return VideoWidgetTest::sceneWithTitle(s_testArray[_currentUISceneId]);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
|
@ -106,6 +106,9 @@ enum
|
||||||
KUIFocusTest_NestedLayout1,
|
KUIFocusTest_NestedLayout1,
|
||||||
KUIFocusTest_NestedLayout2,
|
KUIFocusTest_NestedLayout2,
|
||||||
KUIFocusTest_NestedLayout3,
|
KUIFocusTest_NestedLayout3,
|
||||||
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
||||||
|
kUIVideoWidgetTest,
|
||||||
|
#endif
|
||||||
kUITestMax
|
kUITestMax
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,211 @@
|
||||||
|
#include "UiVideoWidgetTest.h"
|
||||||
|
|
||||||
|
USING_NS_CC;
|
||||||
|
using namespace cocos2d::experimental::ui;
|
||||||
|
|
||||||
|
bool VideoWidgetTest::init()
|
||||||
|
{
|
||||||
|
if ( !UIScene::init() )
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
_visibleRect = Director::getInstance()->getOpenGLView()->getVisibleRect();
|
||||||
|
|
||||||
|
MenuItemFont::setFontSize(16);
|
||||||
|
|
||||||
|
auto fullSwitch = MenuItemFont::create("FullScreenSwitch", CC_CALLBACK_1(VideoWidgetTest::menuFullScreenCallback, this));
|
||||||
|
fullSwitch->setAnchorPoint(Vector2::ANCHOR_BOTTOM_LEFT);
|
||||||
|
fullSwitch->setPosition(Vector2(_visibleRect.origin.x + 10,_visibleRect.origin.y + 50));
|
||||||
|
|
||||||
|
auto pauseItem = MenuItemFont::create("Pause", CC_CALLBACK_1(VideoWidgetTest::menuPauseCallback, this));
|
||||||
|
pauseItem->setAnchorPoint(Vector2::ANCHOR_BOTTOM_LEFT);
|
||||||
|
pauseItem->setPosition(Vector2(_visibleRect.origin.x + 10,_visibleRect.origin.y + 100));
|
||||||
|
|
||||||
|
auto resumeItem = MenuItemFont::create("Resume", CC_CALLBACK_1(VideoWidgetTest::menuResumeCallback, this));
|
||||||
|
resumeItem->setAnchorPoint(Vector2::ANCHOR_BOTTOM_LEFT);
|
||||||
|
resumeItem->setPosition(Vector2(_visibleRect.origin.x + 10,_visibleRect.origin.y + 150));
|
||||||
|
|
||||||
|
auto stopItem = MenuItemFont::create("Stop", CC_CALLBACK_1(VideoWidgetTest::menuStopCallback, this));
|
||||||
|
stopItem->setAnchorPoint(Vector2::ANCHOR_BOTTOM_LEFT);
|
||||||
|
stopItem->setPosition(Vector2(_visibleRect.origin.x + 10,_visibleRect.origin.y + 200));
|
||||||
|
|
||||||
|
auto hintItem = MenuItemFont::create("Hint", CC_CALLBACK_1(VideoWidgetTest::menuHintCallback, this));
|
||||||
|
hintItem->setAnchorPoint(Vector2::ANCHOR_BOTTOM_LEFT);
|
||||||
|
hintItem->setPosition(Vector2(_visibleRect.origin.x + 10,_visibleRect.origin.y + 250));
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------------------------------------------------
|
||||||
|
auto resourceVideo = MenuItemFont::create("Play resource video", CC_CALLBACK_1(VideoWidgetTest::menuResourceVideoCallback, this));
|
||||||
|
resourceVideo->setAnchorPoint(Vector2::ANCHOR_MIDDLE_RIGHT);
|
||||||
|
resourceVideo->setPosition(Vector2(_visibleRect.origin.x + _visibleRect.size.width - 10,_visibleRect.origin.y + 50));
|
||||||
|
|
||||||
|
auto onlineVideo = MenuItemFont::create("Play online video", CC_CALLBACK_1(VideoWidgetTest::menuOnlineVideoCallback, this));
|
||||||
|
onlineVideo->setAnchorPoint(Vector2::ANCHOR_MIDDLE_RIGHT);
|
||||||
|
onlineVideo->setPosition(Vector2(_visibleRect.origin.x + _visibleRect.size.width - 10,_visibleRect.origin.y + 100));
|
||||||
|
|
||||||
|
auto ratioSwitch = MenuItemFont::create("KeepRatioSwitch", CC_CALLBACK_1(VideoWidgetTest::menuRatioCallback, this));
|
||||||
|
ratioSwitch->setAnchorPoint(Vector2::ANCHOR_MIDDLE_RIGHT);
|
||||||
|
ratioSwitch->setPosition(Vector2(_visibleRect.origin.x + _visibleRect.size.width - 10,_visibleRect.origin.y + 150));
|
||||||
|
|
||||||
|
auto menu = Menu::create(resourceVideo,onlineVideo,ratioSwitch,fullSwitch,pauseItem,resumeItem,stopItem,hintItem,nullptr);
|
||||||
|
menu->setPosition(Vector2::ZERO);
|
||||||
|
_uiLayer->addChild(menu);
|
||||||
|
|
||||||
|
_videoStateLabel = Label::createWithSystemFont("IDLE","Arial",16);
|
||||||
|
_videoStateLabel->setAnchorPoint(Vector2::ANCHOR_MIDDLE_RIGHT);
|
||||||
|
_videoStateLabel->setPosition(Vector2(_visibleRect.origin.x + _visibleRect.size.width - 10,_visibleRect.origin.y + 200));
|
||||||
|
_uiLayer->addChild(_videoStateLabel);
|
||||||
|
createVideo();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void VideoWidgetTest::menuCloseCallback(Ref* sender)
|
||||||
|
{
|
||||||
|
Director::getInstance()->end();
|
||||||
|
|
||||||
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
||||||
|
exit(0);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void VideoWidgetTest::menuFullScreenCallback(Ref* sender)
|
||||||
|
{
|
||||||
|
if (_videoWidget)
|
||||||
|
{
|
||||||
|
_videoWidget->setFullScreenEnabled(! _videoWidget->isFullScreenEnabled());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void VideoWidgetTest::menuRatioCallback(Ref* sender)
|
||||||
|
{
|
||||||
|
if (_videoWidget)
|
||||||
|
{
|
||||||
|
_videoWidget->setKeepAspectRatioEnabled(! _videoWidget->isKeepAspectRatioEnabled());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void VideoWidgetTest::menuResourceVideoCallback(Ref* sender)
|
||||||
|
{
|
||||||
|
if (_videoWidget)
|
||||||
|
{
|
||||||
|
_videoWidget->setVideoFileName("cocosvideo.mp4");
|
||||||
|
_videoWidget->startVideo();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void VideoWidgetTest::menuOnlineVideoCallback(Ref* sender)
|
||||||
|
{
|
||||||
|
if (_videoWidget)
|
||||||
|
{
|
||||||
|
_videoWidget->setVideoURL("http://video001.smgbb.cn/gslb/program/FDN/FDN1190949/HLSVodService.m3u8?_mdCode=6065719&_cdnCode=B2B_XL_TEST&_type=0&_rCode=TerOut_18865&_userId=020341000456068&_categoryCode=SMG_HUAYU&_categoryPath=SMG_1002,SMG_HUAYU,&_adPositionId=01001000&_adCategorySource=0&_flag=.m3u8&_enCode=m3u8&taskID=ysh_ps_002-ott_1397459105893_020341000456068&_client=103&_cms=ctv&_CDNToken=76C043FD4969501754DC19E54EC8DC2C");
|
||||||
|
_videoWidget->startVideo();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void VideoWidgetTest::menuPauseCallback(Ref* sender)
|
||||||
|
{
|
||||||
|
if (_videoWidget)
|
||||||
|
{
|
||||||
|
_videoWidget->pauseVideo();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void VideoWidgetTest::menuResumeCallback(Ref* sender)
|
||||||
|
{
|
||||||
|
if (_videoWidget)
|
||||||
|
{
|
||||||
|
_videoWidget->resumeVideo();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void VideoWidgetTest::menuStopCallback(Ref* sender)
|
||||||
|
{
|
||||||
|
if (_videoWidget)
|
||||||
|
{
|
||||||
|
_videoWidget->stopVideo();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void VideoWidgetTest::menuHintCallback(Ref* sender)
|
||||||
|
{
|
||||||
|
if (_videoWidget)
|
||||||
|
{
|
||||||
|
_videoWidget->setVisible(! _videoWidget->isVisible());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void VideoWidgetTest::createVideo()
|
||||||
|
{
|
||||||
|
auto centerPos = Vector2(_visibleRect.origin.x + _visibleRect.size.width / 2,_visibleRect.origin.y + _visibleRect.size.height /2);
|
||||||
|
|
||||||
|
auto widgetSize = _widget->getSize();
|
||||||
|
|
||||||
|
_videoWidget = VideoWidget::create();
|
||||||
|
_videoWidget->setPosition(centerPos);
|
||||||
|
_videoWidget->setAnchorPoint(Vector2::ANCHOR_MIDDLE);
|
||||||
|
_videoWidget->setContentSize(Size(widgetSize.width * 0.4f,widgetSize.height * 0.4f));
|
||||||
|
_uiLayer->addChild(_videoWidget);
|
||||||
|
|
||||||
|
_videoWidget->setEventListener(CC_CALLBACK_2(VideoWidgetTest::videoEventCallback, this));
|
||||||
|
}
|
||||||
|
|
||||||
|
void VideoWidgetTest::createSlider()
|
||||||
|
{
|
||||||
|
auto centerPos = Vector2(_visibleRect.origin.x + _visibleRect.size.width / 2,_visibleRect.origin.y + _visibleRect.size.height /2);
|
||||||
|
|
||||||
|
auto hSlider = ui::Slider::create();
|
||||||
|
hSlider->setTouchEnabled(true);
|
||||||
|
hSlider->loadBarTexture("cocosui/sliderTrack.png");
|
||||||
|
hSlider->loadSlidBallTextures("cocosui/sliderThumb.png", "cocosui/sliderThumb.png", "");
|
||||||
|
hSlider->loadProgressBarTexture("cocosui/sliderProgress.png");
|
||||||
|
hSlider->setPosition(Vector2(centerPos.x, _visibleRect.origin.y + _visibleRect.size.height * 0.15f));
|
||||||
|
hSlider->setPercent(50);
|
||||||
|
hSlider->addEventListenerSlider(this, sliderpercentchangedselector(VideoWidgetTest::sliderCallback));
|
||||||
|
_uiLayer->addChild(hSlider,0,1);
|
||||||
|
|
||||||
|
auto vSlider = ui::Slider::create();
|
||||||
|
vSlider->setTouchEnabled(true);
|
||||||
|
vSlider->loadBarTexture("cocosui/sliderTrack.png");
|
||||||
|
vSlider->loadSlidBallTextures("cocosui/sliderThumb.png", "cocosui/sliderThumb.png", "");
|
||||||
|
vSlider->loadProgressBarTexture("cocosui/sliderProgress.png");
|
||||||
|
vSlider->setPosition(Vector2(_visibleRect.origin.x + _visibleRect.size.width * 0.15f, centerPos.y));
|
||||||
|
vSlider->setRotation(90);
|
||||||
|
vSlider->setPercent(50);
|
||||||
|
vSlider->addEventListenerSlider(this, sliderpercentchangedselector(VideoWidgetTest::sliderCallback));
|
||||||
|
_uiLayer->addChild(vSlider,0,2);
|
||||||
|
}
|
||||||
|
|
||||||
|
void VideoWidgetTest::sliderCallback(Ref *sender, ui::SliderEventType eventType)
|
||||||
|
{
|
||||||
|
if (eventType == SLIDER_PERCENTCHANGED && _videoWidget)
|
||||||
|
{
|
||||||
|
Slider* hSlider = (Slider*)this->getChildByTag(1);
|
||||||
|
Slider* vSlider = (Slider*)this->getChildByTag(2);
|
||||||
|
|
||||||
|
auto newPosX = _visibleRect.origin.x + _visibleRect.size.width / 2 + hSlider->getPercent() - 50;
|
||||||
|
auto newPosY = _visibleRect.origin.y + _visibleRect.size.height / 2 + 50 - vSlider->getPercent();
|
||||||
|
|
||||||
|
_videoWidget->setPosition(Vector2(newPosX,newPosY));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void VideoWidgetTest::videoEventCallback(Ref* sender, VideoWidgetEvent eventType)
|
||||||
|
{
|
||||||
|
switch (eventType) {
|
||||||
|
case VideoWidgetEvent::PLAYING:
|
||||||
|
_videoStateLabel->setString("PLAYING");
|
||||||
|
break;
|
||||||
|
case VideoWidgetEvent::PAUSED:
|
||||||
|
_videoStateLabel->setString("PAUSED");
|
||||||
|
break;
|
||||||
|
case VideoWidgetEvent::STOPPED:
|
||||||
|
_videoStateLabel->setString("STOPPED");
|
||||||
|
break;
|
||||||
|
case VideoWidgetEvent::COMPLETED:
|
||||||
|
_videoStateLabel->setString("COMPLETED");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,44 @@
|
||||||
|
#ifndef __tests__VideoWidgetTest__
|
||||||
|
#define __tests__VideoWidgetTest__
|
||||||
|
|
||||||
|
#include "../UIScene.h"
|
||||||
|
|
||||||
|
USING_NS_CC;
|
||||||
|
|
||||||
|
class VideoWidgetTest : public UIScene
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
UI_SCENE_CREATE_FUNC(VideoWidgetTest);
|
||||||
|
|
||||||
|
virtual bool init();
|
||||||
|
|
||||||
|
void menuCloseCallback(Ref* sender);
|
||||||
|
|
||||||
|
void menuRatioCallback(Ref* sender);
|
||||||
|
void menuResourceVideoCallback(Ref* sender);
|
||||||
|
void menuOnlineVideoCallback(Ref* sender);
|
||||||
|
|
||||||
|
void menuFullScreenCallback(Ref* sender);
|
||||||
|
void menuPauseCallback(Ref* sender);
|
||||||
|
void menuResumeCallback(Ref* sender);
|
||||||
|
void menuStopCallback(Ref* sender);
|
||||||
|
void menuHintCallback(Ref* sender);
|
||||||
|
|
||||||
|
void sliderCallback(Ref *sender, ui::SliderEventType eventType);
|
||||||
|
|
||||||
|
void videoEventCallback(Ref* sender, experimental::ui::VideoWidgetEvent eventType);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void createVideo();
|
||||||
|
void createSlider();
|
||||||
|
|
||||||
|
MenuItemFont* _hintItem;
|
||||||
|
experimental::ui::VideoWidget* _videoWidget;
|
||||||
|
Label* _videoStateLabel;
|
||||||
|
Rect _visibleRect;
|
||||||
|
|
||||||
|
Layer* _rootLayer;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // __tests__VideoWidgetTest__
|
Binary file not shown.
Loading…
Reference in New Issue