2014-05-09 11:30:07 +08:00
|
|
|
/****************************************************************************
|
2016-08-05 09:42:15 +08:00
|
|
|
Copyright (c) 2014-2016 Chukong Technologies Inc.
|
2014-05-09 11:30:07 +08:00
|
|
|
|
|
|
|
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_
|
|
|
|
|
2016-04-28 09:49:55 +08:00
|
|
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_TIZEN) && !defined(CC_PLATFORM_OS_TVOS)
|
2014-05-09 11:30:07 +08:00
|
|
|
|
|
|
|
#include "ui/UIWidget.h"
|
|
|
|
|
2015-03-24 14:12:58 +08:00
|
|
|
/**
|
|
|
|
* @addtogroup ui
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2014-05-09 11:30:07 +08:00
|
|
|
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.
|
2015-03-30 21:38:32 +08:00
|
|
|
* @js NA
|
2015-03-19 10:38:12 +08:00
|
|
|
*/
|
2014-05-09 11:30:07 +08:00
|
|
|
class VideoPlayer : public cocos2d::ui::Widget
|
|
|
|
{
|
|
|
|
public:
|
2015-03-27 20:56:12 +08:00
|
|
|
/**
|
|
|
|
* Videoplayer play event type.
|
|
|
|
*/
|
2014-05-12 11:35:57 +08:00
|
|
|
enum class EventType
|
2014-05-09 11:30:07 +08:00
|
|
|
{
|
|
|
|
PLAYING = 0,
|
|
|
|
PAUSED,
|
|
|
|
STOPPED,
|
|
|
|
COMPLETED
|
|
|
|
};
|
2015-03-27 20:56:12 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A callback which will be called after specific VideoPlayer event happens.
|
|
|
|
*/
|
2014-05-14 11:18:11 +08:00
|
|
|
typedef std::function<void(Ref*,VideoPlayer::EventType)> ccVideoPlayerCallback;
|
2014-05-09 11:30:07 +08:00
|
|
|
|
2015-03-27 20:56:12 +08:00
|
|
|
/**
|
|
|
|
*Static create method for instancing a VideoPlayer.
|
|
|
|
*/
|
2014-05-09 11:30:07 +08:00
|
|
|
CREATE_FUNC(VideoPlayer);
|
|
|
|
|
2015-03-24 14:12:58 +08:00
|
|
|
/**
|
|
|
|
* Sets a file path as a video source for VideoPlayer.
|
|
|
|
*/
|
2014-05-14 11:18:11 +08:00
|
|
|
virtual void setFileName(const std::string& videoPath);
|
2015-03-27 20:56:12 +08:00
|
|
|
|
|
|
|
/**
|
2015-10-23 15:37:33 +08:00
|
|
|
* @brief Get the local video file name.
|
2015-03-27 20:56:12 +08:00
|
|
|
*
|
|
|
|
* @return The video file name.
|
|
|
|
*/
|
2014-05-14 11:18:11 +08:00
|
|
|
virtual const std::string& getFileName() const { return _videoURL;}
|
2014-05-09 11:30:07 +08:00
|
|
|
|
2015-03-24 14:12:58 +08:00
|
|
|
/**
|
|
|
|
* Sets a URL as a video source for VideoPlayer.
|
|
|
|
*/
|
2014-05-14 11:18:11 +08:00
|
|
|
virtual void setURL(const std::string& _videoURL);
|
2015-03-24 14:12:58 +08:00
|
|
|
|
2015-03-27 20:56:12 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Get the URL of remoting video source.
|
|
|
|
*
|
|
|
|
* @return A remoting URL address.
|
|
|
|
*/
|
2014-05-14 11:18:11 +08:00
|
|
|
virtual const std::string& getURL() const { return _videoURL;}
|
2014-05-09 11:30:07 +08:00
|
|
|
|
2015-03-24 14:12:58 +08:00
|
|
|
/**
|
|
|
|
* Starts playback.
|
|
|
|
*/
|
2014-05-14 11:18:11 +08:00
|
|
|
virtual void play();
|
2015-03-24 14:12:58 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Pauses playback.
|
|
|
|
*/
|
2015-07-15 12:04:48 +08:00
|
|
|
virtual void pause()override;
|
2015-03-24 14:12:58 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Resumes playback.
|
|
|
|
*/
|
2015-07-15 12:04:48 +08:00
|
|
|
virtual void resume()override;
|
2015-03-24 14:12:58 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Stops playback.
|
|
|
|
*/
|
2014-05-14 11:18:11 +08:00
|
|
|
virtual void stop();
|
2014-05-09 11:30:07 +08:00
|
|
|
|
2015-03-24 14:12:58 +08:00
|
|
|
/**
|
|
|
|
* Seeks to specified time position.
|
|
|
|
*
|
|
|
|
* @param sec The offset in seconds from the start to seek to.
|
|
|
|
*/
|
2014-05-14 11:18:11 +08:00
|
|
|
virtual void seekTo(float sec);
|
2014-05-09 11:30:07 +08:00
|
|
|
|
2015-03-24 14:12:58 +08:00
|
|
|
/**
|
|
|
|
* Checks whether the VideoPlayer is playing.
|
|
|
|
*
|
|
|
|
* @return True if currently playing, false otherwise.
|
|
|
|
*/
|
|
|
|
virtual bool isPlaying() const;
|
2014-05-09 11:30:07 +08:00
|
|
|
|
2015-03-24 14:12:58 +08:00
|
|
|
/**
|
|
|
|
* Causes the video player to keep aspect ratio or no when displaying the video.
|
|
|
|
*
|
|
|
|
* @param enable Specify true to keep aspect ratio or false to scale the video until
|
|
|
|
* both dimensions fit the visible bounds of the view exactly.
|
|
|
|
*/
|
2014-05-09 11:30:07 +08:00
|
|
|
virtual void setKeepAspectRatioEnabled(bool enable);
|
2015-03-24 14:12:58 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Indicates whether the video player keep aspect ratio when displaying the video.
|
|
|
|
*/
|
2014-05-27 11:17:13 +08:00
|
|
|
virtual bool isKeepAspectRatioEnabled()const { return _keepAspectRatioEnabled;}
|
2014-05-09 11:30:07 +08:00
|
|
|
|
2015-03-24 14:12:58 +08:00
|
|
|
/**
|
|
|
|
* Causes the video player to enter or exit full-screen mode.
|
|
|
|
*
|
|
|
|
* @param fullscreen Specify true to enter full-screen mode or false to exit full-screen mode.
|
|
|
|
*/
|
|
|
|
virtual void setFullScreenEnabled(bool fullscreen);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Indicates whether the video player is in full-screen mode.
|
|
|
|
*
|
|
|
|
* @return True if the video player is in full-screen mode, false otherwise.
|
|
|
|
*/
|
2014-05-27 11:17:13 +08:00
|
|
|
virtual bool isFullScreenEnabled()const;
|
2014-05-09 11:30:07 +08:00
|
|
|
|
2015-03-24 14:12:58 +08:00
|
|
|
/**
|
|
|
|
* Register a callback to be invoked when the video state is updated.
|
|
|
|
*
|
|
|
|
* @param callback The callback that will be run.
|
|
|
|
*/
|
2014-05-14 11:18:11 +08:00
|
|
|
virtual void addEventListener(const VideoPlayer::ccVideoPlayerCallback& callback);
|
2015-03-27 20:56:12 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief A function which will be called when video is playing.
|
|
|
|
*
|
|
|
|
* @param event @see VideoPlayer::EventType.
|
|
|
|
|
|
|
|
*/
|
2014-07-17 21:10:26 +08:00
|
|
|
virtual void onPlayEvent(int event);
|
2015-03-24 14:12:58 +08:00
|
|
|
virtual void setVisible(bool visible) override;
|
2014-06-03 07:02:54 +08:00
|
|
|
virtual void draw(Renderer *renderer, const Mat4& transform, uint32_t flags) override;
|
2016-05-05 10:20:00 +08:00
|
|
|
virtual void onEnter() override;
|
|
|
|
virtual void onExit() 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;
|
|
|
|
|
2014-10-30 14:24:37 +08:00
|
|
|
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
|
2014-09-11 15:39:56 +08:00
|
|
|
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
|
|
|
|
2014-05-14 11:26:04 +08:00
|
|
|
void* _videoView;
|
2014-05-09 11:30:07 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_CC_END
|
2015-03-24 14:12:58 +08:00
|
|
|
// end group
|
|
|
|
/// @}
|
2014-05-09 11:30:07 +08:00
|
|
|
#endif
|
|
|
|
#endif
|