UIVideoPlayer.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. /****************************************************************************
  2. Copyright (c) 2014-2016 Chukong Technologies Inc.
  3. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
  4. http://www.cocos2d-x.org
  5. Permission is hereby granted, free of charge, to any person obtaining a copy
  6. of this software and associated documentation files (the "Software"), to deal
  7. in the Software without restriction, including without limitation the rights
  8. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. copies of the Software, and to permit persons to whom the Software is
  10. furnished to do so, subject to the following conditions:
  11. The above copyright notice and this permission notice shall be included in
  12. all copies or substantial portions of the Software.
  13. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. THE SOFTWARE.
  20. ****************************************************************************/
  21. #ifndef __COCOS2D_UI_VIDEOWEIGTH_H_
  22. #define __COCOS2D_UI_VIDEOWEIGTH_H_
  23. #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_TIZEN) && !defined(CC_PLATFORM_OS_TVOS)
  24. #include "ui/UIWidget.h"
  25. /**
  26. * @addtogroup ui
  27. * @{
  28. */
  29. NS_CC_BEGIN
  30. namespace experimental{
  31. namespace ui{
  32. /**
  33. * @class VideoPlayer
  34. * @brief Displays a video file.
  35. *
  36. * @note VideoPlayer displays a video file base on system widget.
  37. * It's mean VideoPlayer displays a video file above all graphical elements of cocos2d-x.
  38. * @js NA
  39. */
  40. class VideoPlayer : public cocos2d::ui::Widget
  41. {
  42. public:
  43. /**
  44. * Videoplayer play event type.
  45. */
  46. enum class EventType
  47. {
  48. PLAYING = 0,
  49. PAUSED,
  50. STOPPED,
  51. COMPLETED
  52. };
  53. /**
  54. * A callback which will be called after specific VideoPlayer event happens.
  55. */
  56. typedef std::function<void(Ref*,VideoPlayer::EventType)> ccVideoPlayerCallback;
  57. /**
  58. *Static create method for instancing a VideoPlayer.
  59. */
  60. CREATE_FUNC(VideoPlayer);
  61. /**
  62. * Sets a file path as a video source for VideoPlayer.
  63. */
  64. virtual void setFileName(const std::string& videoPath);
  65. /**
  66. * @brief Get the local video file name.
  67. *
  68. * @return The video file name.
  69. */
  70. virtual const std::string& getFileName() const { return _videoURL;}
  71. /**
  72. * Sets a URL as a video source for VideoPlayer.
  73. */
  74. virtual void setURL(const std::string& _videoURL);
  75. /**
  76. * @brief Get the URL of remoting video source.
  77. *
  78. * @return A remoting URL address.
  79. */
  80. virtual const std::string& getURL() const { return _videoURL;}
  81. /**
  82. * Starts playback.
  83. */
  84. virtual void play();
  85. /**
  86. * Pauses playback.
  87. */
  88. virtual void pause()override;
  89. /**
  90. * Resumes playback.
  91. */
  92. virtual void resume()override;
  93. /**
  94. * Stops playback.
  95. */
  96. virtual void stop();
  97. /**
  98. * Seeks to specified time position.
  99. *
  100. * @param sec The offset in seconds from the start to seek to.
  101. */
  102. virtual void seekTo(float sec);
  103. /**
  104. * Checks whether the VideoPlayer is playing.
  105. *
  106. * @return True if currently playing, false otherwise.
  107. */
  108. virtual bool isPlaying() const;
  109. /**
  110. * Causes the video player to keep aspect ratio or no when displaying the video.
  111. *
  112. * @param enable Specify true to keep aspect ratio or false to scale the video until
  113. * both dimensions fit the visible bounds of the view exactly.
  114. */
  115. virtual void setKeepAspectRatioEnabled(bool enable);
  116. /**
  117. * Indicates whether the video player keep aspect ratio when displaying the video.
  118. */
  119. virtual bool isKeepAspectRatioEnabled()const { return _keepAspectRatioEnabled;}
  120. /**
  121. * Causes the video player to enter or exit full-screen mode.
  122. *
  123. * @param fullscreen Specify true to enter full-screen mode or false to exit full-screen mode.
  124. */
  125. virtual void setFullScreenEnabled(bool fullscreen);
  126. /**
  127. * Indicates whether the video player is in full-screen mode.
  128. *
  129. * @return True if the video player is in full-screen mode, false otherwise.
  130. */
  131. virtual bool isFullScreenEnabled()const;
  132. /**
  133. * Register a callback to be invoked when the video state is updated.
  134. *
  135. * @param callback The callback that will be run.
  136. */
  137. virtual void addEventListener(const VideoPlayer::ccVideoPlayerCallback& callback);
  138. /**
  139. * @brief A function which will be called when video is playing.
  140. *
  141. * @param event @see VideoPlayer::EventType.
  142. */
  143. virtual void onPlayEvent(int event);
  144. virtual void setVisible(bool visible) override;
  145. virtual void draw(Renderer *renderer, const Mat4& transform, uint32_t flags) override;
  146. virtual void onEnter() override;
  147. virtual void onExit() override;
  148. protected:
  149. virtual cocos2d::ui::Widget* createCloneInstance() override;
  150. virtual void copySpecialProperties(Widget* model) override;
  151. CC_CONSTRUCTOR_ACCESS:
  152. VideoPlayer();
  153. virtual ~VideoPlayer();
  154. protected:
  155. #if CC_VIDEOPLAYER_DEBUG_DRAW
  156. DrawNode *_debugDrawNode;
  157. #endif
  158. enum class Source
  159. {
  160. FILENAME = 0,
  161. URL
  162. };
  163. bool _isPlaying;
  164. bool _fullScreenDirty;
  165. bool _fullScreenEnabled;
  166. bool _keepAspectRatioEnabled;
  167. std::string _videoURL;
  168. Source _videoSource;
  169. int _videoPlayerIndex;
  170. ccVideoPlayerCallback _eventCallback;
  171. void* _videoView;
  172. };
  173. }
  174. }
  175. NS_CC_END
  176. // end group
  177. /// @}
  178. #endif
  179. #endif