diff --git a/build/cocos2d_libs.xcodeproj/project.pbxproj b/build/cocos2d_libs.xcodeproj/project.pbxproj index 6e77fd096a..9c1daa1267 100644 --- a/build/cocos2d_libs.xcodeproj/project.pbxproj +++ b/build/cocos2d_libs.xcodeproj/project.pbxproj @@ -1123,8 +1123,8 @@ 3E26D40518ACB5D100834404 /* CCImage.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3E26D40418ACB5D100834404 /* CCImage.cpp */; }; 3E26D40618ACB5D100834404 /* CCImage.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3E26D40418ACB5D100834404 /* CCImage.cpp */; }; 3E26D40818ACB63900834404 /* CCDevice.mm in Sources */ = {isa = PBXBuildFile; fileRef = 3E26D40718ACB63900834404 /* CCDevice.mm */; }; - 3EA0FB5B191B92CC00B170C8 /* UIVideoWidget.h in Headers */ = {isa = PBXBuildFile; fileRef = 3EA0FB59191B92CC00B170C8 /* UIVideoWidget.h */; }; - 3EA0FB5C191B92CC00B170C8 /* UIVideoWidgetIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = 3EA0FB5A191B92CC00B170C8 /* UIVideoWidgetIOS.mm */; }; + 3EA0FB6B191C841D00B170C8 /* UIVideoPlayer.h in Headers */ = {isa = PBXBuildFile; fileRef = 3EA0FB69191C841D00B170C8 /* UIVideoPlayer.h */; }; + 3EA0FB6C191C841D00B170C8 /* UIVideoPlayerIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = 3EA0FB6A191C841D00B170C8 /* UIVideoPlayerIOS.mm */; }; 460E468118080832000CDD6D /* cocos-ext.h in Headers */ = {isa = PBXBuildFile; fileRef = 46A167D21807AF4D005B8026 /* cocos-ext.h */; }; 460E468218080836000CDD6D /* cocos-ext.h in Headers */ = {isa = PBXBuildFile; fileRef = 46A167D21807AF4D005B8026 /* cocos-ext.h */; }; 460E477B180808F5000CDD6D /* ExtensionMacros.h in Headers */ = {isa = PBXBuildFile; fileRef = 46A168321807AF4E005B8026 /* ExtensionMacros.h */; }; @@ -2316,8 +2316,8 @@ 37936A3E1869B76800E974DD /* writer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = writer.h; sourceTree = ""; }; 3E26D40418ACB5D100834404 /* CCImage.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CCImage.cpp; sourceTree = ""; }; 3E26D40718ACB63900834404 /* CCDevice.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = CCDevice.mm; sourceTree = ""; }; - 3EA0FB59191B92CC00B170C8 /* UIVideoWidget.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIVideoWidget.h; sourceTree = ""; }; - 3EA0FB5A191B92CC00B170C8 /* UIVideoWidgetIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = UIVideoWidgetIOS.mm; sourceTree = ""; }; + 3EA0FB69191C841D00B170C8 /* UIVideoPlayer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIVideoPlayer.h; sourceTree = ""; }; + 3EA0FB6A191C841D00B170C8 /* UIVideoPlayerIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = UIVideoPlayerIOS.mm; sourceTree = ""; }; 46A15FCC1807A544005B8026 /* AUTHORS */ = {isa = PBXFileReference; lastKnownFileType = text; name = AUTHORS; path = ../AUTHORS; sourceTree = ""; }; 46A15FCE1807A544005B8026 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = text; name = README.md; path = ../README.md; sourceTree = ""; }; 46A15FE11807A56F005B8026 /* Export.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Export.h; sourceTree = ""; }; @@ -3977,8 +3977,8 @@ 2905F9E618CF08D000240AA3 /* ui */ = { isa = PBXGroup; children = ( - 3EA0FB59191B92CC00B170C8 /* UIVideoWidget.h */, - 3EA0FB5A191B92CC00B170C8 /* UIVideoWidgetIOS.mm */, + 3EA0FB69191C841D00B170C8 /* UIVideoPlayer.h */, + 3EA0FB6A191C841D00B170C8 /* UIVideoPlayerIOS.mm */, 2905F9E918CF08D000240AA3 /* CocosGUI.cpp */, 2905F9EA18CF08D000240AA3 /* CocosGUI.h */, 2905F9EB18CF08D000240AA3 /* GUIDefine.h */, @@ -5474,7 +5474,6 @@ 1A5701A0180BCB590088DEC7 /* CCFont.h in Headers */, 1A5701A4180BCB590088DEC7 /* CCFontAtlas.h in Headers */, 1A5701A8180BCB590088DEC7 /* CCFontAtlasCache.h in Headers */, - 3EA0FB5B191B92CC00B170C8 /* UIVideoWidget.h in Headers */, 500DC98919106300007B91BF /* CCNS.h in Headers */, 1A5701B4180BCB590088DEC7 /* CCFontFNT.h in Headers */, 1A5701B8180BCB5A0088DEC7 /* CCFontFreeType.h in Headers */, @@ -5618,6 +5617,7 @@ B2AF2FAC18EBAEAE00C5807C /* Vector4.h in Headers */, 5027253B190BF1B900AAF4ED /* cocos2d.h in Headers */, 1AD71DFC180E26E600808F54 /* CCNodeLoaderListener.h in Headers */, + 3EA0FB6B191C841D00B170C8 /* UIVideoPlayer.h in Headers */, 1AD71E00180E26E600808F54 /* CCParticleSystemQuadLoader.h in Headers */, 1AD71E04180E26E600808F54 /* CCScale9SpriteLoader.h in Headers */, 1AD71E08180E26E600808F54 /* CCScrollViewLoader.h in Headers */, @@ -6553,6 +6553,7 @@ 500DC92B19106300007B91BF /* atitc.cpp in Sources */, 46A170FE1807CECB005B8026 /* CCPhysicsContact.cpp in Sources */, 46A170391807CBFE005B8026 /* CCThread.cpp in Sources */, + 3EA0FB6C191C841D00B170C8 /* UIVideoPlayerIOS.mm in Sources */, 46A170421807CC07005B8026 /* CCGLView.mm in Sources */, 1A570062180BC5A10088DEC7 /* CCAction.cpp in Sources */, 1A570066180BC5A10088DEC7 /* CCActionCamera.cpp in Sources */, @@ -6564,7 +6565,6 @@ 50FCEB9818C72017004AD434 /* CheckBoxReader.cpp in Sources */, 1A570076180BC5A10088DEC7 /* CCActionGrid3D.cpp in Sources */, 500DC99D19106300007B91BF /* CCValue.cpp in Sources */, - 3EA0FB5C191B92CC00B170C8 /* UIVideoWidgetIOS.mm in Sources */, B37510851823ACA100B3BA6A /* CCPhysicsWorldInfo_chipmunk.cpp in Sources */, 1A57007A180BC5A10088DEC7 /* CCActionInstant.cpp in Sources */, 1A57007E180BC5A10088DEC7 /* CCActionInterval.cpp in Sources */, diff --git a/build/cocos2d_tests.xcodeproj/project.pbxproj b/build/cocos2d_tests.xcodeproj/project.pbxproj index 8042d5055b..52d75cef22 100644 --- a/build/cocos2d_tests.xcodeproj/project.pbxproj +++ b/build/cocos2d_tests.xcodeproj/project.pbxproj @@ -813,8 +813,8 @@ 29080DE5191B595E0066F8DF /* UIWidgetAddNodeTest_Editor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 29080D8B191B595E0066F8DF /* UIWidgetAddNodeTest_Editor.cpp */; }; 29080DE6191B595E0066F8DF /* UIWidgetAddNodeTest_Editor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 29080D8B191B595E0066F8DF /* UIWidgetAddNodeTest_Editor.cpp */; }; 3EA0FB5E191B92F100B170C8 /* cocosvideo.mp4 in Resources */ = {isa = PBXBuildFile; fileRef = 3EA0FB5D191B92F100B170C8 /* cocosvideo.mp4 */; }; - 3EA0FB64191B931500B170C8 /* UIVideoWidgetTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3EA0FB62191B931500B170C8 /* UIVideoWidgetTest.cpp */; }; 3EA0FB66191B933000B170C8 /* MediaPlayer.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3EA0FB65191B933000B170C8 /* MediaPlayer.framework */; }; + 3EA0FB72191C844400B170C8 /* UIVideoPlayerTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3EA0FB70191C844400B170C8 /* UIVideoPlayerTest.cpp */; }; A05FCACA177C124500BE600E /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 15C64822165F391E007D4F18 /* Cocoa.framework */; }; A07A521E1783A1D20073F6A7 /* libz.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 15C6482E165F399D007D4F18 /* libz.dylib */; }; A07A521F1783A1D20073F6A7 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 15C64832165F3AFD007D4F18 /* Foundation.framework */; }; @@ -1848,9 +1848,9 @@ 29080D8B191B595E0066F8DF /* UIWidgetAddNodeTest_Editor.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UIWidgetAddNodeTest_Editor.cpp; sourceTree = ""; }; 29080D8C191B595E0066F8DF /* UIWidgetAddNodeTest_Editor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIWidgetAddNodeTest_Editor.h; sourceTree = ""; }; 3EA0FB5D191B92F100B170C8 /* cocosvideo.mp4 */ = {isa = PBXFileReference; lastKnownFileType = file; name = cocosvideo.mp4; path = "../tests/cpp-tests/Resources/cocosvideo.mp4"; sourceTree = ""; }; - 3EA0FB62191B931500B170C8 /* UIVideoWidgetTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UIVideoWidgetTest.cpp; sourceTree = ""; }; - 3EA0FB63191B931500B170C8 /* UIVideoWidgetTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIVideoWidgetTest.h; sourceTree = ""; }; 3EA0FB65191B933000B170C8 /* MediaPlayer.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MediaPlayer.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.1.sdk/System/Library/Frameworks/MediaPlayer.framework; sourceTree = DEVELOPER_DIR; }; + 3EA0FB70191C844400B170C8 /* UIVideoPlayerTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UIVideoPlayerTest.cpp; sourceTree = ""; }; + 3EA0FB71191C844400B170C8 /* UIVideoPlayerTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIVideoPlayerTest.h; sourceTree = ""; }; 46A15F9C1807A4F8005B8026 /* cocos2d_libs.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; path = cocos2d_libs.xcodeproj; sourceTree = ""; }; A035A71117822E9E00987F6C /* libsqlite3.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libsqlite3.dylib; path = usr/lib/libsqlite3.dylib; sourceTree = SDKROOT; }; A07A52291783A1D20073F6A7 /* cpp-tests iOS.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "cpp-tests iOS.app"; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -3471,7 +3471,7 @@ 29080D1E191B595E0066F8DF /* CocoStudioGUITest */ = { isa = PBXGroup; children = ( - 3EA0FB61191B931500B170C8 /* UIVideoWidgetTest */, + 3EA0FB6F191C844400B170C8 /* UIVideoPlayerTest */, 29080D1F191B595E0066F8DF /* CocosGUIScene.cpp */, 29080D20191B595E0066F8DF /* CocosGUIScene.h */, 29080D21191B595E0066F8DF /* CocoStudioGUITest.cpp */, @@ -3780,13 +3780,13 @@ name = Frameworks; sourceTree = ""; }; - 3EA0FB61191B931500B170C8 /* UIVideoWidgetTest */ = { + 3EA0FB6F191C844400B170C8 /* UIVideoPlayerTest */ = { isa = PBXGroup; children = ( - 3EA0FB62191B931500B170C8 /* UIVideoWidgetTest.cpp */, - 3EA0FB63191B931500B170C8 /* UIVideoWidgetTest.h */, + 3EA0FB70191C844400B170C8 /* UIVideoPlayerTest.cpp */, + 3EA0FB71191C844400B170C8 /* UIVideoPlayerTest.h */, ); - path = UIVideoWidgetTest; + path = UIVideoPlayerTest; sourceTree = ""; }; 46A15F9D1807A4F8005B8026 /* Products */ = { @@ -4795,7 +4795,6 @@ 1AC35B4218CECF0C00F37B72 /* QuestionContainerSprite.cpp in Sources */, 1AC35B6218CECF0C00F37B72 /* DrawPrimitivesTest.cpp in Sources */, 29080DDC191B595E0066F8DF /* UITextFieldTest.cpp in Sources */, - 3EA0FB64191B931500B170C8 /* UIVideoWidgetTest.cpp in Sources */, 1AC35C1818CECF0C00F37B72 /* MotionStreakTest.cpp in Sources */, 1AC35C0618CECF0C00F37B72 /* FontTest.cpp in Sources */, 1AC35C3818CECF0C00F37B72 /* PerformanceTest.cpp in Sources */, @@ -4849,6 +4848,7 @@ 1AC35C8618CECF1400F37B72 /* RootViewController.mm in Sources */, 1AC35C5C18CECF0C00F37B72 /* TileMapTest.cpp in Sources */, 29080DC2191B595E0066F8DF /* UIRichTextTest.cpp in Sources */, + 3EA0FB72191C844400B170C8 /* UIVideoPlayerTest.cpp in Sources */, 1AC35B4818CECF0C00F37B72 /* Bug-899.cpp in Sources */, 1AC35C1C18CECF0C00F37B72 /* NewEventDispatcherTest.cpp in Sources */, 1AC35C2E18CECF0C00F37B72 /* PerformanceNodeChildrenTest.cpp in Sources */, diff --git a/cocos/ui/Android.mk b/cocos/ui/Android.mk index e83f35e8ea..d80df7efa8 100644 --- a/cocos/ui/Android.mk +++ b/cocos/ui/Android.mk @@ -29,7 +29,7 @@ CCProtectedNode.cpp \ UIHBox.cpp \ UIVBox.cpp \ UIRelativeBox.cpp \ -UIVideoWidgetAndroid.cpp +UIVideoPlayerAndroid.cpp LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/.. \ $(LOCAL_PATH)/../editor-support diff --git a/cocos/ui/CocosGUI.h b/cocos/ui/CocosGUI.h index 992c8d910b..c9572c5af7 100644 --- a/cocos/ui/CocosGUI.h +++ b/cocos/ui/CocosGUI.h @@ -46,7 +46,7 @@ THE SOFTWARE. #include "ui/UIVBox.h" #include "ui/UIRelativeBox.h" #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS) -#include "ui/UIVideoWidget.h" +#include "ui/UIVideoPlayer.h" #endif NS_CC_BEGIN diff --git a/cocos/ui/UIVideoPlayer.h b/cocos/ui/UIVideoPlayer.h new file mode 100644 index 0000000000..b011e0f95a --- /dev/null +++ b/cocos/ui/UIVideoPlayer.h @@ -0,0 +1,113 @@ +/**************************************************************************** + Copyright (c) 2014 Chukong Technologies Inc. + + http://www.cocos2d-x.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ + +#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" + +NS_CC_BEGIN +namespace experimental{ + namespace ui{ + + class VideoPlayer : public cocos2d::ui::Widget + { + public: + enum class Event + { + PLAYING = 0, + PAUSED, + STOPPED, + COMPLETED + }; + typedef std::function EventCallback; + + CREATE_FUNC(VideoPlayer); + + //Sets local file[support assets' file on android] as a video source for VideoPlayer + virtual void setVideoFileName(const std::string& videoPath); + virtual const std::string& getVideoFileName() const { return _videoUrl;} + + //Sets network link as a video source for VideoPlayer + virtual void setVideoURL(const std::string& videoUrl); + virtual const std::string& getVideoURL() const { return _videoUrl;} + + virtual void startVideo(); + virtual void pauseVideo(); + virtual void resumeVideo(); + virtual void stopVideo(); + + virtual void seekVideoTo(float sec); + virtual bool isPlaying() const; + + virtual void setVisible(bool visible) override; + + virtual void setKeepAspectRatioEnabled(bool enable); + virtual bool isKeepAspectRatioEnabled() { return _keepAspectRatioEnabled;} + + virtual void setFullScreenEnabled(bool enabled); + virtual bool isFullScreenEnabled(); + + virtual void setEventListener(const EventCallback& callback); + + virtual void onVideoEvent(VideoPlayer::Event event); + virtual void draw(Renderer *renderer, const Matrix& transform, bool transformUpdated) override; + + protected: + VideoPlayer(); + virtual ~VideoPlayer(); + +#if CC_VIDEOPLAYER_DEBUG_DRAW + CustomCommand _customDebugDrawCommand; + void VideoPlayer::drawDebugData(); +#endif + + enum class VideoSource + { + FILENAME = 0, + URL + }; + + bool _isPlaying; + bool _fullScreenDirty; + bool _fullScreenEnabled; + bool _keepAspectRatioEnabled; + + std::string _videoUrl; + VideoSource _videoSource; + + int _videoPlayerIndex; + EventCallback _callback; + + void* _videiView; + }; + } +} + +NS_CC_END + +#endif +#endif diff --git a/cocos/ui/UIVideoWidgetAndroid.cpp b/cocos/ui/UIVideoPlayerAndroid.cpp similarity index 78% rename from cocos/ui/UIVideoWidgetAndroid.cpp rename to cocos/ui/UIVideoPlayerAndroid.cpp index 596f77b100..8942defd12 100644 --- a/cocos/ui/UIVideoWidgetAndroid.cpp +++ b/cocos/ui/UIVideoPlayerAndroid.cpp @@ -22,7 +22,7 @@ THE SOFTWARE. ****************************************************************************/ -#include "UIVideoWidget.h" +#include "UIVideoPlayer.h" #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) #include @@ -152,20 +152,20 @@ void setVideoKeepRatioEnabled(int index,bool enabled) using namespace cocos2d::experimental::ui; -static std::unordered_map s_allVideoWidgets; +static std::unordered_map s_allVideoPlayers; -VideoWidget::VideoWidget() -: _videoWidgetIndex(-1) +VideoPlayer::VideoPlayer() +: _videoPlayerIndex(-1) , _callback(nullptr) , _fullScreenEnabled(false) , _fullScreenDirty(false) , _keepAspectRatioEnabled(false) { - _videoWidgetIndex = createVideoWidgetJNI(); - s_allVideoWidgets[_videoWidgetIndex] = this; + _videoPlayerIndex = createVideoWidgetJNI(); + s_allVideoPlayers[_videoPlayerIndex] = this; auto listener = EventListenerKeyboard::create(); - listener->onKeyReleased = [&](EventKeyboard::KeyCode keycode, Event* event){ + listener->onKeyReleased = [&](EventKeyboard::KeyCode keycode, cocos2d::Event* event){ if (keycode == EventKeyboard::KeyCode::KEY_BACKSPACE && _fullScreenEnabled) { this->setFullScreenEnabled(false); @@ -175,27 +175,27 @@ VideoWidget::VideoWidget() _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this); } -VideoWidget::~VideoWidget() +VideoPlayer::~VideoPlayer() { - s_allVideoWidgets.erase(_videoWidgetIndex); - removeVideoWidgetJNI(_videoWidgetIndex); + s_allVideoPlayers.erase(_videoPlayerIndex); + removeVideoWidgetJNI(_videoPlayerIndex); } -void VideoWidget::setVideoFileName(const std::string& fileName) +void VideoPlayer::setVideoFileName(const std::string& fileName) { _videoUrl = fileName; - _videoSource = VideoWidget::VideoSource::FILENAME; - setVideoURLJNI(_videoWidgetIndex, (int)VideoSource::FILENAME,_videoUrl); + _videoSource = VideoPlayer::VideoSource::FILENAME; + setVideoURLJNI(_videoPlayerIndex, (int)VideoSource::FILENAME,_videoUrl); } -void VideoWidget::setVideoURL(const std::string& videoUrl) +void VideoPlayer::setVideoURL(const std::string& videoUrl) { _videoUrl = videoUrl; - _videoSource = VideoWidget::VideoSource::URL; - setVideoURLJNI(_videoWidgetIndex,(int)VideoSource::URL,_videoUrl); + _videoSource = VideoPlayer::VideoSource::URL; + setVideoURLJNI(_videoPlayerIndex,(int)VideoSource::URL,_videoUrl); } -void VideoWidget::draw(Renderer* renderer, const Matrix &transform, bool transformUpdated) +void VideoPlayer::draw(Renderer* renderer, const Matrix &transform, bool transformUpdated) { cocos2d::ui::Widget::draw(renderer,transform,transformUpdated); @@ -208,7 +208,7 @@ void VideoWidget::draw(Renderer* renderer, const Matrix &transform, bool transfo if (_fullScreenEnabled) { - setVideoRectJNI(_videoWidgetIndex,0,0,frameSize.width,frameSize.height); + setVideoRectJNI(_videoPlayerIndex,0,0,frameSize.width,frameSize.height); } else { @@ -220,20 +220,20 @@ void VideoWidget::draw(Renderer* renderer, const Matrix &transform, bool transfo auto uiLeft = frameSize.width / 2 + (leftBottom.x - winSize.width / 2 ) * glView->getScaleX(); auto uiTop = frameSize.height /2 - (rightTop.y - winSize.height / 2) * glView->getScaleY(); - setVideoRectJNI(_videoWidgetIndex,uiLeft,uiTop, + setVideoRectJNI(_videoPlayerIndex,uiLeft,uiTop, (rightTop.x - leftBottom.x) * glView->getScaleX(), (rightTop.y - leftBottom.y) * glView->getScaleY()); } } -#if CC_VIDEOWIDGET_DEBUG_DRAW +#if CC_VIDEOPLAYER_DEBUG_DRAW _customDebugDrawCommand.init(_globalZOrder); - _customDebugDrawCommand.func = CC_CALLBACK_0(VideoWidget::drawDebugData, this); + _customDebugDrawCommand.func = CC_CALLBACK_0(VideoPlayer::drawDebugData, this); renderer->addCommand(&_customDebugDrawCommand); #endif } -void VideoWidget::setFullScreenEnabled(bool enabled) +void VideoPlayer::setFullScreenEnabled(bool enabled) { if (_fullScreenEnabled != enabled) { @@ -242,22 +242,22 @@ void VideoWidget::setFullScreenEnabled(bool enabled) } } -bool VideoWidget::isFullScreenEnabled() +bool VideoPlayer::isFullScreenEnabled() { return _fullScreenEnabled; } -void VideoWidget::setKeepAspectRatioEnabled(bool enable) +void VideoPlayer::setKeepAspectRatioEnabled(bool enable) { if (_keepAspectRatioEnabled != enable) { _keepAspectRatioEnabled = enable; - setVideoKeepRatioEnabled(_videoWidgetIndex,enable); + setVideoKeepRatioEnabled(_videoPlayerIndex,enable); } } -#if CC_VIDEOWIDGET_DEBUG_DRAW -void VideoWidget::drawDebugData() +#if CC_VIDEOPLAYER_DEBUG_DRAW +void VideoPlayer::drawDebugData() { Director* director = Director::getInstance(); CCASSERT(nullptr != director, "Director is null when seting matrix stack"); @@ -281,69 +281,69 @@ void VideoWidget::drawDebugData() } #endif -void VideoWidget::startVideo() +void VideoPlayer::startVideo() { if (! _videoUrl.empty()) { - startVideoJNI(_videoWidgetIndex); + startVideoJNI(_videoPlayerIndex); } } -void VideoWidget::pauseVideo() +void VideoPlayer::pauseVideo() { if (! _videoUrl.empty()) { - pauseVideoJNI(_videoWidgetIndex); + pauseVideoJNI(_videoPlayerIndex); } } -void VideoWidget::resumeVideo() +void VideoPlayer::resumeVideo() { if (! _videoUrl.empty()) { - resumeVideoJNI(_videoWidgetIndex); + resumeVideoJNI(_videoPlayerIndex); } } -void VideoWidget::stopVideo() +void VideoPlayer::stopVideo() { if (! _videoUrl.empty()) { - stopVideoJNI(_videoWidgetIndex); + stopVideoJNI(_videoPlayerIndex); } } -void VideoWidget::seekVideoTo(float sec) +void VideoPlayer::seekVideoTo(float sec) { if (! _videoUrl.empty()) { - seekVideoToJNI(_videoWidgetIndex,int(sec * 1000)); + seekVideoToJNI(_videoPlayerIndex,int(sec * 1000)); } } -bool VideoWidget::isPlaying() const +bool VideoPlayer::isPlaying() const { return _isPlaying; } -void VideoWidget::setVisible(bool visible) +void VideoPlayer::setVisible(bool visible) { cocos2d::ui::Widget::setVisible(visible); if (! _videoUrl.empty()) { - setVideoVisible(_videoWidgetIndex,visible); + setVideoVisible(_videoPlayerIndex,visible); } } -void VideoWidget::setEventListener(const VideoWidgetCallback& callback) +void VideoPlayer::setEventListener(const EventCallback& callback) { _callback = callback; } -void VideoWidget::onVideoEvent(VideoWidgetEvent event) +void VideoPlayer::onVideoEvent(VideoPlayer::Event event) { - if (event == VideoWidgetEvent::PLAYING) { + if (event == VideoPlayer::Event::PLAYING) { _isPlaying = true; } else { _isPlaying = false; @@ -357,10 +357,10 @@ void VideoWidget::onVideoEvent(VideoWidgetEvent event) void executeVideoCallback(int index,int event) { - auto it = s_allVideoWidgets.find(index); - if (it != s_allVideoWidgets.end()) + auto it = s_allVideoPlayers.find(index); + if (it != s_allVideoPlayers.end()) { - s_allVideoWidgets[index]->onVideoEvent((VideoWidgetEvent)event); + s_allVideoPlayers[index]->onVideoEvent((VideoPlayer::Event)event); } } diff --git a/cocos/ui/UIVideoWidgetIOS.mm b/cocos/ui/UIVideoPlayerIOS.mm similarity index 87% rename from cocos/ui/UIVideoWidgetIOS.mm rename to cocos/ui/UIVideoPlayerIOS.mm index 361bc8d977..85b663953c 100644 --- a/cocos/ui/UIVideoWidgetIOS.mm +++ b/cocos/ui/UIVideoPlayerIOS.mm @@ -22,9 +22,11 @@ THE SOFTWARE. ****************************************************************************/ -#include "UIVideoWidget.h" +#include "UIVideoPlayer.h" #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS) + +using namespace cocos2d::experimental::ui; //------------------------------------------------------------------------------------- #include "CCEAGLView.h" #import @@ -45,7 +47,7 @@ - (void) setFullScreenEnabled:(bool) enabled; - (bool) isFullScreenEnabled; --(id) init:(void*) widget; +-(id) init:(void*) videoPlayer; -(void) videoFinished:(NSNotification*) notification; -(void) playStateChange; @@ -62,14 +64,14 @@ int _height; bool _keepRatioEnabled; - cocos2d::experimental::ui::VideoWidget* _widget; + VideoPlayer* _videoPlayer; } --(id)init:(void*)widget +-(id)init:(void*)videoPlayer { if (self = [super init]) { self.moviePlayer = nullptr; - _widget = (cocos2d::experimental::ui::VideoWidget*)widget; + _videoPlayer = (VideoPlayer*)videoPlayer; _keepRatioEnabled = false; } @@ -85,7 +87,7 @@ [self.moviePlayer stop]; [self.moviePlayer.view removeFromSuperview]; self.moviePlayer = nullptr; - _widget = nullptr; + _videoPlayer = nullptr; } [super dealloc]; } @@ -163,11 +165,11 @@ -(void) videoFinished:(NSNotification *)notification { - if(_widget != nullptr) + if(_videoPlayer != nullptr) { if([self.moviePlayer playbackState] != MPMoviePlaybackStateStopped) { - _widget->onVideoEvent(cocos2d::experimental::ui::VideoWidgetEvent::COMPLETED); + _videoPlayer->onVideoEvent(VideoPlayer::Event::COMPLETED); } } } @@ -177,13 +179,13 @@ MPMoviePlaybackState state = [self.moviePlayer playbackState]; switch (state) { case MPMoviePlaybackStatePaused: - _widget->onVideoEvent(cocos2d::experimental::ui::VideoWidgetEvent::PAUSED); + _videoPlayer->onVideoEvent(VideoPlayer::Event::PAUSED); break; case MPMoviePlaybackStateStopped: - _widget->onVideoEvent(cocos2d::experimental::ui::VideoWidgetEvent::STOPPED); + _videoPlayer->onVideoEvent(VideoPlayer::Event::STOPPED); break; case MPMoviePlaybackStatePlaying: - _widget->onVideoEvent(cocos2d::experimental::ui::VideoWidgetEvent::PLAYING); + _videoPlayer->onVideoEvent(VideoPlayer::Event::PLAYING); break; case MPMoviePlaybackStateInterrupted: break; @@ -277,10 +279,8 @@ @end //------------------------------------------------------------------------------------------------------------ -using namespace cocos2d::experimental::ui; - -VideoWidget::VideoWidget() -: _videoWidgetIndex(-1) +VideoPlayer::VideoPlayer() +: _videoPlayerIndex(-1) , _callback(nullptr) , _fullScreenEnabled(false) , _fullScreenDirty(false) @@ -290,7 +290,7 @@ VideoWidget::VideoWidget() _videiView = [[UIVideoViewWrapperIos alloc] init:this]; } -VideoWidget::~VideoWidget() +VideoPlayer::~VideoPlayer() { if(_videiView) { @@ -298,21 +298,21 @@ VideoWidget::~VideoWidget() } } -void VideoWidget::setVideoFileName(const std::string& fileName) +void VideoPlayer::setVideoFileName(const std::string& fileName) { _videoUrl = fileName; - _videoSource = VideoWidget::VideoSource::FILENAME; + _videoSource = VideoPlayer::VideoSource::FILENAME; [((UIVideoViewWrapperIos*)_videiView) setVideoURL:(int)_videoSource :_videoUrl]; } -void VideoWidget::setVideoURL(const std::string& videoUrl) +void VideoPlayer::setVideoURL(const std::string& videoUrl) { _videoUrl = videoUrl; - _videoSource = VideoWidget::VideoSource::URL; + _videoSource = VideoPlayer::VideoSource::URL; [((UIVideoViewWrapperIos*)_videiView) setVideoURL:(int)_videoSource :_videoUrl]; } -void VideoWidget::draw(Renderer* renderer, const Matrix &transform, bool transformUpdated) +void VideoPlayer::draw(Renderer* renderer, const Matrix &transform, bool transformUpdated) { cocos2d::ui::Widget::draw(renderer,transform,transformUpdated); @@ -336,24 +336,24 @@ void VideoWidget::draw(Renderer* renderer, const Matrix &transform, bool transfo :( (rightTop.y - leftBottom.y) * glView->getScaleY()/scaleFactor)]; } -#if CC_VIDEOWIDGET_DEBUG_DRAW +#if CC_VIDEOPLAYER_DEBUG_DRAW _customDebugDrawCommand.init(_globalZOrder); - _customDebugDrawCommand.func = CC_CALLBACK_0(VideoWidget::drawDebugData, this); + _customDebugDrawCommand.func = CC_CALLBACK_0(VideoPlayer::drawDebugData, this); renderer->addCommand(&_customDebugDrawCommand); #endif } -bool VideoWidget::isFullScreenEnabled() +bool VideoPlayer::isFullScreenEnabled() { return [((UIVideoViewWrapperIos*)_videiView) isFullScreenEnabled]; } -void VideoWidget::setFullScreenEnabled(bool enabled) +void VideoPlayer::setFullScreenEnabled(bool enabled) { [((UIVideoViewWrapperIos*)_videiView) setFullScreenEnabled:enabled]; } -void VideoWidget::setKeepAspectRatioEnabled(bool enable) +void VideoPlayer::setKeepAspectRatioEnabled(bool enable) { if (_keepAspectRatioEnabled != enable) { @@ -362,8 +362,8 @@ void VideoWidget::setKeepAspectRatioEnabled(bool enable) } } -#if CC_VIDEOWIDGET_DEBUG_DRAW -void VideoWidget::drawDebugData() +#if CC_VIDEOPLAYER_DEBUG_DRAW +void VideoPlayer::drawDebugData() { Director* director = Director::getInstance(); CCASSERT(nullptr != director, "Director is null when seting matrix stack"); @@ -387,7 +387,7 @@ void VideoWidget::drawDebugData() } #endif -void VideoWidget::startVideo() +void VideoPlayer::startVideo() { if (! _videoUrl.empty()) { @@ -395,7 +395,7 @@ void VideoWidget::startVideo() } } -void VideoWidget::pauseVideo() +void VideoPlayer::pauseVideo() { if (! _videoUrl.empty()) { @@ -403,7 +403,7 @@ void VideoWidget::pauseVideo() } } -void VideoWidget::resumeVideo() +void VideoPlayer::resumeVideo() { if (! _videoUrl.empty()) { @@ -411,7 +411,7 @@ void VideoWidget::resumeVideo() } } -void VideoWidget::stopVideo() +void VideoPlayer::stopVideo() { if (! _videoUrl.empty()) { @@ -419,7 +419,7 @@ void VideoWidget::stopVideo() } } -void VideoWidget::seekVideoTo(float sec) +void VideoPlayer::seekVideoTo(float sec) { if (! _videoUrl.empty()) { @@ -427,12 +427,12 @@ void VideoWidget::seekVideoTo(float sec) } } -bool VideoWidget::isPlaying() const +bool VideoPlayer::isPlaying() const { return _isPlaying; } -void VideoWidget::setVisible(bool visible) +void VideoPlayer::setVisible(bool visible) { cocos2d::ui::Widget::setVisible(visible); @@ -442,14 +442,14 @@ void VideoWidget::setVisible(bool visible) } } -void VideoWidget::setEventListener(const VideoWidgetCallback& callback) +void VideoPlayer::setEventListener(const EventCallback& callback) { _callback = callback; } -void VideoWidget::onVideoEvent(VideoWidgetEvent event) +void VideoPlayer::onVideoEvent(VideoPlayer::Event event) { - if (event == VideoWidgetEvent::PLAYING) { + if (event == VideoPlayer::Event::PLAYING) { _isPlaying = true; } else { _isPlaying = false; diff --git a/cocos/ui/UIVideoWidget.h b/cocos/ui/UIVideoWidget.h deleted file mode 100644 index 0189046784..0000000000 --- a/cocos/ui/UIVideoWidget.h +++ /dev/null @@ -1,115 +0,0 @@ -/**************************************************************************** - Copyright (c) 2014 Chukong Technologies Inc. - - http://www.cocos2d-x.org - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - ****************************************************************************/ - -#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" - -NS_CC_BEGIN -namespace experimental{ -namespace ui{ - - enum class VideoWidgetEvent - { - PLAYING = 0, - PAUSED, - STOPPED, - COMPLETED - }; - - typedef std::function VideoWidgetCallback; - - class VideoWidget : public cocos2d::ui::Widget - { - public: - - CREATE_FUNC(VideoWidget); - - //Sets local file[support assets' file on android] as a video source for VideoWidget - virtual void setVideoFileName(const std::string& videoPath); - virtual const std::string& getVideoFileName() const { return _videoUrl;} - - //Sets network link as a video source for VideoWidget - virtual void setVideoURL(const std::string& videoUrl); - virtual const std::string& getVideoURL() const { return _videoUrl;} - - virtual void startVideo(); - virtual void pauseVideo(); - virtual void resumeVideo(); - virtual void stopVideo(); - - virtual void seekVideoTo(float sec); - virtual bool isPlaying() const; - - virtual void setVisible(bool visible) override; - - virtual void setKeepAspectRatioEnabled(bool enable); - virtual bool isKeepAspectRatioEnabled() { return _keepAspectRatioEnabled;} - - virtual void setFullScreenEnabled(bool enabled); - virtual bool isFullScreenEnabled(); - - virtual void setEventListener(const VideoWidgetCallback& callback); - - virtual void onVideoEvent(VideoWidgetEvent event); - virtual void draw(Renderer *renderer, const Matrix& transform, bool transformUpdated) override; - - protected: - VideoWidget(); - virtual ~VideoWidget(); - -#if CC_VIDEOWIDGET_DEBUG_DRAW - CustomCommand _customDebugDrawCommand; - void VideoWidget::drawDebugData(); -#endif - - enum class VideoSource - { - FILENAME = 0, - URL - }; - - bool _isPlaying; - bool _fullScreenDirty; - bool _fullScreenEnabled; - bool _keepAspectRatioEnabled; - - std::string _videoUrl; - VideoSource _videoSource; - - int _videoWidgetIndex; - VideoWidgetCallback _callback; - - void* _videiView; - }; -} -} - -NS_CC_END - -#endif -#endif diff --git a/tests/cpp-tests/Android.mk b/tests/cpp-tests/Android.mk index 87612034d7..8299f055bf 100644 --- a/tests/cpp-tests/Android.mk +++ b/tests/cpp-tests/Android.mk @@ -98,7 +98,7 @@ Classes/UITest/CocoStudioGUITest/UITextAtlasTest/UITextAtlasTest_Editor.cpp \ Classes/UITest/CocoStudioGUITest/UITextBMFontTest/UITextBMFontTest_Editor.cpp \ Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp \ Classes/UITest/CocoStudioGUITest/UIWidgetAddNodeTest/UIWidgetAddNodeTest_Editor.cpp \ -Classes/UITest/CocoStudioGUITest/UIVideoWidgetTest/UIVideoWidgetTest.cpp \ +Classes/UITest/CocoStudioGUITest/UIVideoPlayerTest/UIVideoPlayerTest.cpp \ Classes/UITest/CocoStudioGUITest/CustomWidget/CustomImageView.cpp \ Classes/UITest/CocoStudioGUITest/CustomWidget/CustomImageViewReader.cpp \ Classes/UITest/CocoStudioGUITest/CustomWidget/CustomParticleWidget.cpp \ diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CocosGUIScene.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CocosGUIScene.cpp index aa56eb262b..614649a83c 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CocosGUIScene.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/CocosGUIScene.cpp @@ -281,13 +281,13 @@ g_guisTests[] = }, #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS) { - "gui VideoWidgetTest", + "gui VideoPlayerTest", [](Ref* sender) { UISceneManager* pManager = UISceneManager::sharedUISceneManager(); - pManager->setCurrentUISceneId(kUIVideoWidgetTest); - pManager->setMinUISceneId(kUIVideoWidgetTest); - pManager->setMaxUISceneId(kUIVideoWidgetTest); + pManager->setCurrentUISceneId(kUIVideoPlayerTest); + pManager->setMinUISceneId(kUIVideoPlayerTest); + pManager->setMaxUISceneId(kUIVideoPlayerTest); Scene* pScene = pManager->currentUIScene(); Director::getInstance()->replaceScene(pScene); } diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager.cpp index 65ff70cb2c..4ca3c47d53 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager.cpp @@ -19,7 +19,7 @@ #include "UIRichTextTest/UIRichTextTest.h" #include "UIFocusTest/UIFocusTest.h" #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS) -#include "UIVideoWidgetTest/UIVideoWidgetTest.h" +#include "UIVideoPlayerTest/UIVideoPlayerTest.h" #endif /* #include "UISwitchTest/UISwitchTest.h" @@ -119,7 +119,7 @@ static const char* s_testArray[] = "UIFocusTest-NestedLayout2", "UIFocusTest-NestedLayout3", #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS) - "UIVideoWidgetTest" + "UIVideoPlayerTest" #endif }; @@ -382,8 +382,8 @@ Scene *UISceneManager::currentUIScene() case KUIFocusTest_NestedLayout3: 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]); + case kUIVideoPlayerTest: + return VideoPlayerTest::sceneWithTitle(s_testArray[_currentUISceneId]); #endif } return NULL; diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager.h index 7461440b62..b3f179b5a7 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISceneManager.h @@ -107,7 +107,7 @@ enum KUIFocusTest_NestedLayout2, KUIFocusTest_NestedLayout3, #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS) - kUIVideoWidgetTest, + kUIVideoPlayerTest, #endif kUITestMax }; diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIVideoWidgetTest/UIVideoWidgetTest.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIVideoPlayerTest/UIVideoPlayerTest.cpp similarity index 68% rename from tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIVideoWidgetTest/UIVideoWidgetTest.cpp rename to tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIVideoPlayerTest/UIVideoPlayerTest.cpp index fe859fbaf0..d3771787e9 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIVideoWidgetTest/UIVideoWidgetTest.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIVideoPlayerTest/UIVideoPlayerTest.cpp @@ -1,9 +1,9 @@ -#include "UIVideoWidgetTest.h" +#include "UIVideoPlayerTest.h" USING_NS_CC; using namespace cocos2d::experimental::ui; -bool VideoWidgetTest::init() +bool VideoPlayerTest::init() { if ( !UIScene::init() ) { @@ -14,36 +14,36 @@ bool VideoWidgetTest::init() MenuItemFont::setFontSize(16); - auto fullSwitch = MenuItemFont::create("FullScreenSwitch", CC_CALLBACK_1(VideoWidgetTest::menuFullScreenCallback, this)); + auto fullSwitch = MenuItemFont::create("FullScreenSwitch", CC_CALLBACK_1(VideoPlayerTest::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)); + auto pauseItem = MenuItemFont::create("Pause", CC_CALLBACK_1(VideoPlayerTest::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)); + auto resumeItem = MenuItemFont::create("Resume", CC_CALLBACK_1(VideoPlayerTest::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)); + auto stopItem = MenuItemFont::create("Stop", CC_CALLBACK_1(VideoPlayerTest::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)); + auto hintItem = MenuItemFont::create("Hint", CC_CALLBACK_1(VideoPlayerTest::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)); + auto resourceVideo = MenuItemFont::create("Play resource video", CC_CALLBACK_1(VideoPlayerTest::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)); + auto onlineVideo = MenuItemFont::create("Play online video", CC_CALLBACK_1(VideoPlayerTest::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)); + auto ratioSwitch = MenuItemFont::create("KeepRatioSwitch", CC_CALLBACK_1(VideoPlayerTest::menuRatioCallback, this)); ratioSwitch->setAnchorPoint(Vector2::ANCHOR_MIDDLE_RIGHT); ratioSwitch->setPosition(Vector2(_visibleRect.origin.x + _visibleRect.size.width - 10,_visibleRect.origin.y + 150)); @@ -60,7 +60,7 @@ bool VideoWidgetTest::init() return true; } -void VideoWidgetTest::menuCloseCallback(Ref* sender) +void VideoPlayerTest::menuCloseCallback(Ref* sender) { Director::getInstance()->end(); @@ -69,88 +69,88 @@ void VideoWidgetTest::menuCloseCallback(Ref* sender) #endif } -void VideoWidgetTest::menuFullScreenCallback(Ref* sender) +void VideoPlayerTest::menuFullScreenCallback(Ref* sender) { - if (_videoWidget) + if (_videoPlayer) { - _videoWidget->setFullScreenEnabled(! _videoWidget->isFullScreenEnabled()); + _videoPlayer->setFullScreenEnabled(! _videoPlayer->isFullScreenEnabled()); } } -void VideoWidgetTest::menuRatioCallback(Ref* sender) +void VideoPlayerTest::menuRatioCallback(Ref* sender) { - if (_videoWidget) + if (_videoPlayer) { - _videoWidget->setKeepAspectRatioEnabled(! _videoWidget->isKeepAspectRatioEnabled()); + _videoPlayer->setKeepAspectRatioEnabled(! _videoPlayer->isKeepAspectRatioEnabled()); } } -void VideoWidgetTest::menuResourceVideoCallback(Ref* sender) +void VideoPlayerTest::menuResourceVideoCallback(Ref* sender) { - if (_videoWidget) + if (_videoPlayer) { - _videoWidget->setVideoFileName("cocosvideo.mp4"); - _videoWidget->startVideo(); + _videoPlayer->setVideoFileName("cocosvideo.mp4"); + _videoPlayer->startVideo(); } } -void VideoWidgetTest::menuOnlineVideoCallback(Ref* sender) +void VideoPlayerTest::menuOnlineVideoCallback(Ref* sender) { - if (_videoWidget) + if (_videoPlayer) { - _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(); + _videoPlayer->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"); + _videoPlayer->startVideo(); } } -void VideoWidgetTest::menuPauseCallback(Ref* sender) +void VideoPlayerTest::menuPauseCallback(Ref* sender) { - if (_videoWidget) + if (_videoPlayer) { - _videoWidget->pauseVideo(); + _videoPlayer->pauseVideo(); } } -void VideoWidgetTest::menuResumeCallback(Ref* sender) +void VideoPlayerTest::menuResumeCallback(Ref* sender) { - if (_videoWidget) + if (_videoPlayer) { - _videoWidget->resumeVideo(); + _videoPlayer->resumeVideo(); } } -void VideoWidgetTest::menuStopCallback(Ref* sender) +void VideoPlayerTest::menuStopCallback(Ref* sender) { - if (_videoWidget) + if (_videoPlayer) { - _videoWidget->stopVideo(); + _videoPlayer->stopVideo(); } } -void VideoWidgetTest::menuHintCallback(Ref* sender) +void VideoPlayerTest::menuHintCallback(Ref* sender) { - if (_videoWidget) + if (_videoPlayer) { - _videoWidget->setVisible(! _videoWidget->isVisible()); + _videoPlayer->setVisible(! _videoPlayer->isVisible()); } } -void VideoWidgetTest::createVideo() +void VideoPlayerTest::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); + _videoPlayer = VideoPlayer::create(); + _videoPlayer->setPosition(centerPos); + _videoPlayer->setAnchorPoint(Vector2::ANCHOR_MIDDLE); + _videoPlayer->setContentSize(Size(widgetSize.width * 0.4f,widgetSize.height * 0.4f)); + _uiLayer->addChild(_videoPlayer); - _videoWidget->setEventListener(CC_CALLBACK_2(VideoWidgetTest::videoEventCallback, this)); + _videoPlayer->setEventListener(CC_CALLBACK_2(VideoPlayerTest::videoEventCallback, this)); } -void VideoWidgetTest::createSlider() +void VideoPlayerTest::createSlider() { auto centerPos = Vector2(_visibleRect.origin.x + _visibleRect.size.width / 2,_visibleRect.origin.y + _visibleRect.size.height /2); @@ -161,7 +161,7 @@ void VideoWidgetTest::createSlider() 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)); + hSlider->addEventListenerSlider(this, sliderpercentchangedselector(VideoPlayerTest::sliderCallback)); _uiLayer->addChild(hSlider,0,1); auto vSlider = ui::Slider::create(); @@ -172,13 +172,13 @@ void VideoWidgetTest::createSlider() 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)); + vSlider->addEventListenerSlider(this, sliderpercentchangedselector(VideoPlayerTest::sliderCallback)); _uiLayer->addChild(vSlider,0,2); } -void VideoWidgetTest::sliderCallback(Ref *sender, ui::SliderEventType eventType) +void VideoPlayerTest::sliderCallback(Ref *sender, ui::SliderEventType eventType) { - if (eventType == SLIDER_PERCENTCHANGED && _videoWidget) + if (eventType == SLIDER_PERCENTCHANGED && _videoPlayer) { Slider* hSlider = (Slider*)this->getChildByTag(1); Slider* vSlider = (Slider*)this->getChildByTag(2); @@ -186,23 +186,23 @@ void VideoWidgetTest::sliderCallback(Ref *sender, ui::SliderEventType eventType) 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)); + _videoPlayer->setPosition(Vector2(newPosX,newPosY)); } } -void VideoWidgetTest::videoEventCallback(Ref* sender, VideoWidgetEvent eventType) +void VideoPlayerTest::videoEventCallback(Ref* sender, VideoPlayer::Event eventType) { switch (eventType) { - case VideoWidgetEvent::PLAYING: + case VideoPlayer::Event::PLAYING: _videoStateLabel->setString("PLAYING"); break; - case VideoWidgetEvent::PAUSED: + case VideoPlayer::Event::PAUSED: _videoStateLabel->setString("PAUSED"); break; - case VideoWidgetEvent::STOPPED: + case VideoPlayer::Event::STOPPED: _videoStateLabel->setString("STOPPED"); break; - case VideoWidgetEvent::COMPLETED: + case VideoPlayer::Event::COMPLETED: _videoStateLabel->setString("COMPLETED"); break; default: diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIVideoWidgetTest/UIVideoWidgetTest.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIVideoPlayerTest/UIVideoPlayerTest.h similarity index 74% rename from tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIVideoWidgetTest/UIVideoWidgetTest.h rename to tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIVideoPlayerTest/UIVideoPlayerTest.h index 063d398a4f..a587b5303c 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIVideoWidgetTest/UIVideoWidgetTest.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIVideoPlayerTest/UIVideoPlayerTest.h @@ -1,14 +1,14 @@ -#ifndef __tests__VideoWidgetTest__ -#define __tests__VideoWidgetTest__ +#ifndef __tests__VideoPlayerTest__ +#define __tests__VideoPlayerTest__ #include "../UIScene.h" USING_NS_CC; -class VideoWidgetTest : public UIScene +class VideoPlayerTest : public UIScene { public: - UI_SCENE_CREATE_FUNC(VideoWidgetTest); + UI_SCENE_CREATE_FUNC(VideoPlayerTest); virtual bool init(); @@ -26,14 +26,14 @@ public: void sliderCallback(Ref *sender, ui::SliderEventType eventType); - void videoEventCallback(Ref* sender, experimental::ui::VideoWidgetEvent eventType); + void videoEventCallback(Ref* sender, experimental::ui::VideoPlayer::Event eventType); private: void createVideo(); void createSlider(); MenuItemFont* _hintItem; - experimental::ui::VideoWidget* _videoWidget; + experimental::ui::VideoPlayer* _videoPlayer; Label* _videoStateLabel; Rect _visibleRect; @@ -41,4 +41,4 @@ private: }; -#endif // __tests__VideoWidgetTest__ +#endif // __tests__VideoPlayerTest__