ZKVideoView.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * ZKVideoView.h
  3. *
  4. * Created on: Nov 13, 2017
  5. * Author: guoxs
  6. */
  7. #ifndef _CONTROL_ZKVIDEOVIEW_H_
  8. #define _CONTROL_ZKVIDEOVIEW_H_
  9. #include "ZKBase.h"
  10. #include "media/ZKMediaPlayer.h"
  11. class ZKVideoViewPrivate;
  12. /**
  13. * @brief 视频控件
  14. */
  15. class ZKVideoView : public ZKBase {
  16. ZK_DECLARE_PRIVATE(ZKVideoView)
  17. public:
  18. ZKVideoView(ZKBase *pParent);
  19. virtual ~ZKVideoView();
  20. /**
  21. * @brief 播放指定路径视频文件
  22. * @param pFilePath 视频文件路径
  23. * @param msec 指定从哪个位置开始播放,单位为毫秒,默认从头开始播放
  24. */
  25. void play(const char *pFilePath, int msec = 0);
  26. /**
  27. * @brief 暂停播放
  28. */
  29. void pause();
  30. /**
  31. * @brief 恢复播放
  32. */
  33. void resume();
  34. /**
  35. * @brief 定位到msec位置播放
  36. * @param msec 单位为毫秒
  37. */
  38. void seekTo(int msec);
  39. /**
  40. * @brief 停止播放
  41. */
  42. void stop();
  43. /**
  44. * @brief 是否播放中
  45. */
  46. bool isPlaying();
  47. /**
  48. * @brief 设置音量
  49. * @param volume 范围:0.0 ~ 1.0
  50. */
  51. void setVolume(float volume);
  52. void setPosition(const LayoutPosition &position);
  53. /* clockwise rotation: val=0 no rotation, val=1 90 degree; val=2 180 degree, val=3 270 degree */
  54. void setRotation(int val);
  55. /**
  56. * @brief 获取视频总时长,单位为毫秒
  57. */
  58. int getDuration();
  59. /**
  60. * @brief 获取当前播放位置,单位为毫秒
  61. */
  62. int getCurrentPosition();
  63. public:
  64. typedef enum {
  65. E_MSGTYPE_VIDEO_PLAY_STARTED,
  66. E_MSGTYPE_VIDEO_PLAY_COMPLETED,
  67. E_MSGTYPE_VIDEO_PLAY_ERROR
  68. } EMessageType;
  69. /**
  70. * @brief 视频播放状态监听接口
  71. */
  72. class IVideoPlayerMessageListener {
  73. public:
  74. virtual ~IVideoPlayerMessageListener() { }
  75. virtual void onVideoPlayerMessage(ZKVideoView *pVideoView, int msg) = 0;
  76. };
  77. void setVideoPlayerMessageListener(IVideoPlayerMessageListener *pListener) {
  78. mVideoPlayerMessageListenerPtr = pListener;
  79. }
  80. protected:
  81. ZKVideoView(ZKBase *pParent, ZKBasePrivate *pBP);
  82. virtual void onBeforeCreateWindow(const Json::Value &json);
  83. virtual void onAfterCreateWindow(const Json::Value &json);
  84. virtual const char* getClassName() const { return ZK_VIDEOVIEW; }
  85. virtual void onDraw(ZKCanvas *pCanvas);
  86. private:
  87. void parseVideoViewAttributeFromJson(const Json::Value &json);
  88. class PlayerMessageListener : public ZKMediaPlayer::IPlayerMessageListener {
  89. public:
  90. PlayerMessageListener(ZKVideoView *pVideoView) : mVideoViewPtr(pVideoView) { }
  91. virtual void onPlayerMessage(ZKMediaPlayer *pMediaPlayer, int msg, void *pMsgData);
  92. private:
  93. ZKVideoView * const mVideoViewPtr;
  94. };
  95. private:
  96. ZKMediaPlayer *mMediaPlayerPtr;
  97. IVideoPlayerMessageListener *mVideoPlayerMessageListenerPtr;
  98. PlayerMessageListener mPlayerMessageListener;
  99. };
  100. #endif /* _CONTROL_ZKVIDEOVIEW_H_ */