VideoPlayer.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #ifndef VideoPlayer_H
  2. #define VideoPlayer_H
  3. #include <QWidget>
  4. #include <QThread>
  5. #include <QTimer>
  6. #include <QSemaphore>
  7. class DecodeVedio;
  8. class VideoPlayer : public QWidget
  9. {
  10. Q_OBJECT
  11. public:
  12. explicit VideoPlayer(QWidget *parent = nullptr);
  13. ~VideoPlayer();
  14. void setPlayVedio(const QString& fileName); /* 设置播放视频 */
  15. bool play(); /* 播放视频 */
  16. void pause(); /* 暂停播放 */
  17. void stop(); /* 停止播放 */
  18. bool getPlayStatus() { return m_playStatus; } /* 获取播放状态 */
  19. qint64 getDuration(); /* 获取视频时长 */
  20. qint64 getCurrentPos(); /* 获取当前播放位置 */
  21. void setCurrentPos(quint64 pos); /* 设置当前播放位置 */
  22. void setPlayVedioSize(int width,int height); /* 设置播放视频大小 */
  23. // void setPlayCallBack(std::function<Play_CallBack> playCallBack,void* context); /* 设置播放回调函数 */
  24. protected:
  25. void paintEvent(QPaintEvent *event) override;
  26. void resizeEvent(QResizeEvent *event) override;
  27. void refreshOneUIUntilHave(); /* 刷新一张图片,直到有图片为止 */
  28. /* 双击事件函数 */
  29. void mouseDoubleClickEvent(QMouseEvent *event) override;
  30. private slots:
  31. void do_refreshUI(); /* 取出画面,刷新UI */
  32. void do_refreshOneUI(); /* 通过信号刷新第一张图片 */
  33. void do_playCompleted(); /* 播放完成 */
  34. private:
  35. QString m_fileName;
  36. QTimer m_timerRefreshUI; /* 定时器,用于刷新界面 */
  37. int m_srcWidth = 0; /* 图片原本大小 */
  38. int m_srcHeight = 0;
  39. int m_nowWidth = 0; /* 现在大小 */
  40. int m_nowHeight = 0;
  41. int m_frameCount = 0; /* 帧数 */
  42. int m_interval = 0; /* 间隔 */
  43. DecodeVedio* m_decodeVedio = nullptr;
  44. QThread* m_threadDecode = nullptr; /* 解码器所在的线程 */
  45. QImage* m_image = nullptr; /* 画面 */
  46. bool m_playStatus = false; /* 是否正在播放 */
  47. bool isSetVedioFile = false; /* 是否设置了视频文件 */
  48. QSemaphore* m_semRefresh = nullptr; /* 刷新信号量 */
  49. // std::function<Play_CallBack> m_funcPlayCB = nullptr; /* 播放回调函数 */
  50. void* m_context = nullptr; /* 上下文 */
  51. };
  52. #endif /* VideoPlayer_H */