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
{
public:
enum class Event
enum class EventType
{
PLAYING = 0,
PAUSED,
STOPPED,
COMPLETED
};
typedef std::function<void(Ref*,VideoPlayer::Event)> EventCallback;
typedef std::function<void(Ref*,VideoPlayer::EventType)> 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:

View File

@ -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);
}
}

View File

@ -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;

View File

@ -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:

View File

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