From 9d7d06a1f8d4600afd2e740033ba718340de2581 Mon Sep 17 00:00:00 2001 From: andyque Date: Mon, 12 May 2014 11:35:57 +0800 Subject: [PATCH] issue #5047, refactor UIVideoPlayer --- cocos/ui/UIVideoPlayer.h | 8 ++++---- cocos/ui/UIVideoPlayerAndroid.cpp | 6 +++--- cocos/ui/UIVideoPlayerIOS.mm | 14 +++++++------- .../UIVideoPlayerTest/UIVideoPlayerTest.cpp | 12 ++++++------ .../UIVideoPlayerTest/UIVideoPlayerTest.h | 2 +- 5 files changed, 21 insertions(+), 21 deletions(-) diff --git a/cocos/ui/UIVideoPlayer.h b/cocos/ui/UIVideoPlayer.h index b011e0f95a..75f8a164e2 100644 --- a/cocos/ui/UIVideoPlayer.h +++ b/cocos/ui/UIVideoPlayer.h @@ -36,14 +36,14 @@ namespace experimental{ class VideoPlayer : public cocos2d::ui::Widget { public: - enum class Event + enum class EventType { PLAYING = 0, PAUSED, STOPPED, COMPLETED }; - typedef std::function EventCallback; + typedef std::function EventCallback; CREATE_FUNC(VideoPlayer); @@ -71,9 +71,9 @@ namespace experimental{ virtual void setFullScreenEnabled(bool enabled); virtual bool isFullScreenEnabled(); - virtual void setEventListener(const EventCallback& callback); + virtual void addEventListener(const EventCallback& callback); - virtual void onVideoEvent(VideoPlayer::Event event); + virtual void onVideoEvent(VideoPlayer::EventType event); virtual void draw(Renderer *renderer, const Matrix& transform, bool transformUpdated) override; protected: diff --git a/cocos/ui/UIVideoPlayerAndroid.cpp b/cocos/ui/UIVideoPlayerAndroid.cpp index 8942defd12..d2a4c26590 100644 --- a/cocos/ui/UIVideoPlayerAndroid.cpp +++ b/cocos/ui/UIVideoPlayerAndroid.cpp @@ -341,9 +341,9 @@ void VideoPlayer::setEventListener(const EventCallback& callback) _callback = callback; } -void VideoPlayer::onVideoEvent(VideoPlayer::Event event) +void VideoPlayer::onVideoEvent(VideoPlayer::EventType event) { - if (event == VideoPlayer::Event::PLAYING) { + if (event == VideoPlayer::EventType::PLAYING) { _isPlaying = true; } else { _isPlaying = false; @@ -360,7 +360,7 @@ void executeVideoCallback(int index,int event) auto it = s_allVideoPlayers.find(index); if (it != s_allVideoPlayers.end()) { - s_allVideoPlayers[index]->onVideoEvent((VideoPlayer::Event)event); + s_allVideoPlayers[index]->onVideoEvent((VideoPlayer::EventType)event); } } diff --git a/cocos/ui/UIVideoPlayerIOS.mm b/cocos/ui/UIVideoPlayerIOS.mm index 85b663953c..4351146b5b 100644 --- a/cocos/ui/UIVideoPlayerIOS.mm +++ b/cocos/ui/UIVideoPlayerIOS.mm @@ -169,7 +169,7 @@ using namespace cocos2d::experimental::ui; { if([self.moviePlayer playbackState] != MPMoviePlaybackStateStopped) { - _videoPlayer->onVideoEvent(VideoPlayer::Event::COMPLETED); + _videoPlayer->onVideoEvent(VideoPlayer::EventType::COMPLETED); } } } @@ -179,13 +179,13 @@ using namespace cocos2d::experimental::ui; MPMoviePlaybackState state = [self.moviePlayer playbackState]; switch (state) { case MPMoviePlaybackStatePaused: - _videoPlayer->onVideoEvent(VideoPlayer::Event::PAUSED); + _videoPlayer->onVideoEvent(VideoPlayer::EventType::PAUSED); break; case MPMoviePlaybackStateStopped: - _videoPlayer->onVideoEvent(VideoPlayer::Event::STOPPED); + _videoPlayer->onVideoEvent(VideoPlayer::EventType::STOPPED); break; case MPMoviePlaybackStatePlaying: - _videoPlayer->onVideoEvent(VideoPlayer::Event::PLAYING); + _videoPlayer->onVideoEvent(VideoPlayer::EventType::PLAYING); break; case MPMoviePlaybackStateInterrupted: break; @@ -442,14 +442,14 @@ void VideoPlayer::setVisible(bool visible) } } -void VideoPlayer::setEventListener(const EventCallback& callback) +void VideoPlayer::addEventListener(const EventCallback& callback) { _callback = callback; } -void VideoPlayer::onVideoEvent(VideoPlayer::Event event) +void VideoPlayer::onVideoEvent(VideoPlayer::EventType event) { - if (event == VideoPlayer::Event::PLAYING) { + if (event == VideoPlayer::EventType::PLAYING) { _isPlaying = true; } else { _isPlaying = false; diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIVideoPlayerTest/UIVideoPlayerTest.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIVideoPlayerTest/UIVideoPlayerTest.cpp index 7c9712042c..050a6e186f 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIVideoPlayerTest/UIVideoPlayerTest.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIVideoPlayerTest/UIVideoPlayerTest.cpp @@ -147,7 +147,7 @@ void VideoPlayerTest::createVideo() _videoPlayer->setContentSize(Size(widgetSize.width * 0.4f,widgetSize.height * 0.4f)); _uiLayer->addChild(_videoPlayer); - _videoPlayer->setEventListener(CC_CALLBACK_2(VideoPlayerTest::videoEventCallback, this)); + _videoPlayer->addEventListener(CC_CALLBACK_2(VideoPlayerTest::videoEventCallback, this)); } void VideoPlayerTest::createSlider() @@ -190,19 +190,19 @@ void VideoPlayerTest::sliderCallback(Ref *sender, ui::Slider::EventType eventTyp } } -void VideoPlayerTest::videoEventCallback(Ref* sender, VideoPlayer::Event eventType) +void VideoPlayerTest::videoEventCallback(Ref* sender, VideoPlayer::EventType eventType) { switch (eventType) { - case VideoPlayer::Event::PLAYING: + case VideoPlayer::EventType::PLAYING: _videoStateLabel->setString("PLAYING"); break; - case VideoPlayer::Event::PAUSED: + case VideoPlayer::EventType::PAUSED: _videoStateLabel->setString("PAUSED"); break; - case VideoPlayer::Event::STOPPED: + case VideoPlayer::EventType::STOPPED: _videoStateLabel->setString("STOPPED"); break; - case VideoPlayer::Event::COMPLETED: + case VideoPlayer::EventType::COMPLETED: _videoStateLabel->setString("COMPLETED"); break; default: diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIVideoPlayerTest/UIVideoPlayerTest.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIVideoPlayerTest/UIVideoPlayerTest.h index b8ed49dc70..64a06105f9 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIVideoPlayerTest/UIVideoPlayerTest.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIVideoPlayerTest/UIVideoPlayerTest.h @@ -26,7 +26,7 @@ public: void sliderCallback(Ref *sender, ui::Slider::EventType eventType); - void videoEventCallback(Ref* sender, experimental::ui::VideoPlayer::Event eventType); + void videoEventCallback(Ref* sender, experimental::ui::VideoPlayer::EventType eventType); private: void createVideo();