issue #5047, refactor UIVideoPlayer

This commit is contained in:
andyque 2014-05-12 11:35:57 +08:00
parent 4f3c128c4f
commit 9d7d06a1f8
5 changed files with 21 additions and 21 deletions

View File

@ -36,14 +36,14 @@ namespace experimental{
class VideoPlayer : public cocos2d::ui::Widget class VideoPlayer : public cocos2d::ui::Widget
{ {
public: public:
enum class Event enum class EventType
{ {
PLAYING = 0, PLAYING = 0,
PAUSED, PAUSED,
STOPPED, STOPPED,
COMPLETED COMPLETED
}; };
typedef std::function<void(Ref*,VideoPlayer::Event)> EventCallback; typedef std::function<void(Ref*,VideoPlayer::EventType)> EventCallback;
CREATE_FUNC(VideoPlayer); CREATE_FUNC(VideoPlayer);
@ -71,9 +71,9 @@ namespace experimental{
virtual void setFullScreenEnabled(bool enabled); virtual void setFullScreenEnabled(bool enabled);
virtual bool isFullScreenEnabled(); 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; virtual void draw(Renderer *renderer, const Matrix& transform, bool transformUpdated) override;
protected: protected:

View File

@ -341,9 +341,9 @@ void VideoPlayer::setEventListener(const EventCallback& callback)
_callback = 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; _isPlaying = true;
} else { } else {
_isPlaying = false; _isPlaying = false;
@ -360,7 +360,7 @@ void executeVideoCallback(int index,int event)
auto it = s_allVideoPlayers.find(index); auto it = s_allVideoPlayers.find(index);
if (it != s_allVideoPlayers.end()) if (it != s_allVideoPlayers.end())
{ {
s_allVideoPlayers[index]->onVideoEvent((VideoPlayer::Event)event); s_allVideoPlayers[index]->onVideoEvent((VideoPlayer::EventType)event);
} }
} }

View File

@ -169,7 +169,7 @@ using namespace cocos2d::experimental::ui;
{ {
if([self.moviePlayer playbackState] != MPMoviePlaybackStateStopped) 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]; MPMoviePlaybackState state = [self.moviePlayer playbackState];
switch (state) { switch (state) {
case MPMoviePlaybackStatePaused: case MPMoviePlaybackStatePaused:
_videoPlayer->onVideoEvent(VideoPlayer::Event::PAUSED); _videoPlayer->onVideoEvent(VideoPlayer::EventType::PAUSED);
break; break;
case MPMoviePlaybackStateStopped: case MPMoviePlaybackStateStopped:
_videoPlayer->onVideoEvent(VideoPlayer::Event::STOPPED); _videoPlayer->onVideoEvent(VideoPlayer::EventType::STOPPED);
break; break;
case MPMoviePlaybackStatePlaying: case MPMoviePlaybackStatePlaying:
_videoPlayer->onVideoEvent(VideoPlayer::Event::PLAYING); _videoPlayer->onVideoEvent(VideoPlayer::EventType::PLAYING);
break; break;
case MPMoviePlaybackStateInterrupted: case MPMoviePlaybackStateInterrupted:
break; break;
@ -442,14 +442,14 @@ void VideoPlayer::setVisible(bool visible)
} }
} }
void VideoPlayer::setEventListener(const EventCallback& callback) void VideoPlayer::addEventListener(const EventCallback& callback)
{ {
_callback = 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; _isPlaying = true;
} else { } else {
_isPlaying = false; _isPlaying = false;

View File

@ -147,7 +147,7 @@ void VideoPlayerTest::createVideo()
_videoPlayer->setContentSize(Size(widgetSize.width * 0.4f,widgetSize.height * 0.4f)); _videoPlayer->setContentSize(Size(widgetSize.width * 0.4f,widgetSize.height * 0.4f));
_uiLayer->addChild(_videoPlayer); _uiLayer->addChild(_videoPlayer);
_videoPlayer->setEventListener(CC_CALLBACK_2(VideoPlayerTest::videoEventCallback, this)); _videoPlayer->addEventListener(CC_CALLBACK_2(VideoPlayerTest::videoEventCallback, this));
} }
void VideoPlayerTest::createSlider() 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) { switch (eventType) {
case VideoPlayer::Event::PLAYING: case VideoPlayer::EventType::PLAYING:
_videoStateLabel->setString("PLAYING"); _videoStateLabel->setString("PLAYING");
break; break;
case VideoPlayer::Event::PAUSED: case VideoPlayer::EventType::PAUSED:
_videoStateLabel->setString("PAUSED"); _videoStateLabel->setString("PAUSED");
break; break;
case VideoPlayer::Event::STOPPED: case VideoPlayer::EventType::STOPPED:
_videoStateLabel->setString("STOPPED"); _videoStateLabel->setString("STOPPED");
break; break;
case VideoPlayer::Event::COMPLETED: case VideoPlayer::EventType::COMPLETED:
_videoStateLabel->setString("COMPLETED"); _videoStateLabel->setString("COMPLETED");
break; break;
default: default:

View File

@ -26,7 +26,7 @@ public:
void sliderCallback(Ref *sender, ui::Slider::EventType eventType); 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: private:
void createVideo(); void createVideo();