axmol/cocos/ui/UIVideoPlayer.h

125 lines
4.2 KiB
C
Raw Normal View History

2014-05-09 11:30:07 +08:00
/****************************************************************************
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{
2015-03-19 10:38:12 +08:00
/**
* @class VideoPlayer
* @brief Displays a video file.
*
* @note VideoPlayer displays a video file base on system widget.
* It's mean VideoPlayer displays a video file above all graphical elements of cocos2d-x.
*/
2014-05-09 11:30:07 +08:00
class VideoPlayer : public cocos2d::ui::Widget
{
public:
2014-05-12 11:35:57 +08:00
enum class EventType
2014-05-09 11:30:07 +08:00
{
PLAYING = 0,
PAUSED,
STOPPED,
COMPLETED
};
2014-05-14 11:18:11 +08:00
typedef std::function<void(Ref*,VideoPlayer::EventType)> ccVideoPlayerCallback;
2014-05-09 11:30:07 +08:00
CREATE_FUNC(VideoPlayer);
//Sets local file[support assets' file on android] as a video source for VideoPlayer
2014-05-14 11:18:11 +08:00
virtual void setFileName(const std::string& videoPath);
virtual const std::string& getFileName() const { return _videoURL;}
2014-05-09 11:30:07 +08:00
//Sets network link as a video source for VideoPlayer
2014-05-14 11:18:11 +08:00
virtual void setURL(const std::string& _videoURL);
virtual const std::string& getURL() const { return _videoURL;}
2014-05-09 11:30:07 +08:00
2014-05-14 11:18:11 +08:00
virtual void play();
virtual void pause();
virtual void resume();
virtual void stop();
2014-05-09 11:30:07 +08:00
2014-05-14 11:18:11 +08:00
virtual void seekTo(float sec);
2014-05-09 11:30:07 +08:00
virtual bool isPlaying() const;
virtual void setVisible(bool visible) override;
virtual void setKeepAspectRatioEnabled(bool enable);
2014-05-27 11:17:13 +08:00
virtual bool isKeepAspectRatioEnabled()const { return _keepAspectRatioEnabled;}
2014-05-09 11:30:07 +08:00
virtual void setFullScreenEnabled(bool enabled);
2014-05-27 11:17:13 +08:00
virtual bool isFullScreenEnabled()const;
2014-05-09 11:30:07 +08:00
2014-05-14 11:18:11 +08:00
virtual void addEventListener(const VideoPlayer::ccVideoPlayerCallback& callback);
2014-05-09 11:30:07 +08:00
virtual void onPlayEvent(int event);
2014-06-03 07:02:54 +08:00
virtual void draw(Renderer *renderer, const Mat4& transform, uint32_t flags) override;
2014-05-09 11:30:07 +08:00
protected:
2014-05-23 15:03:46 +08:00
virtual cocos2d::ui::Widget* createCloneInstance() override;
virtual void copySpecialProperties(Widget* model) override;
CC_CONSTRUCTOR_ACCESS:
2014-05-09 11:30:07 +08:00
VideoPlayer();
virtual ~VideoPlayer();
2014-10-30 14:38:55 +08:00
protected:
2014-05-09 11:30:07 +08:00
#if CC_VIDEOPLAYER_DEBUG_DRAW
DrawNode *_debugDrawNode;
2014-05-09 11:30:07 +08:00
#endif
2014-05-14 11:18:11 +08:00
enum class Source
2014-05-09 11:30:07 +08:00
{
FILENAME = 0,
URL
};
bool _isPlaying;
bool _fullScreenDirty;
bool _fullScreenEnabled;
bool _keepAspectRatioEnabled;
2014-05-14 11:18:11 +08:00
std::string _videoURL;
Source _videoSource;
2014-05-09 11:30:07 +08:00
int _videoPlayerIndex;
2014-05-14 11:18:11 +08:00
ccVideoPlayerCallback _eventCallback;
2014-05-09 11:30:07 +08:00
void* _videoView;
2014-05-09 11:30:07 +08:00
};
}
}
NS_CC_END
#endif
#endif