SimplePlayerWindow.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #ifndef SIMPLEPLAYERWINDOW_H
  2. #define SIMPLEPLAYERWINDOW_H
  3. #include <QApplication>
  4. #include <QDebug>
  5. #include <QFileDialog>
  6. #include <QHBoxLayout>
  7. #include <QLabel>
  8. #include <QMainWindow>
  9. #include <QMessageBox>
  10. #include <QPushButton>
  11. #include <QSlider>
  12. #include <QTimer>
  13. #include <QVBoxLayout>
  14. #include "player_adapter.h"
  15. #include "video_renderer.h"
  16. using namespace av::player;
  17. /**
  18. * @brief 简单的播放器UI示例
  19. *
  20. * 这个类展示了如何使用新的PlayerAdapter来构建播放器UI
  21. */
  22. class SimplePlayerWindow : public QMainWindow
  23. {
  24. Q_OBJECT
  25. public:
  26. explicit SimplePlayerWindow(QWidget* parent = nullptr);
  27. ~SimplePlayerWindow();
  28. private slots:
  29. void openFile();
  30. void playPause();
  31. void stop();
  32. void seek();
  33. void setVolume();
  34. void toggleMute();
  35. void setPlaybackSpeed();
  36. // 播放器事件处理
  37. void onStateChanged(PlayerState state);
  38. void onMediaInfoChanged(const MediaInfo& info);
  39. void onPositionChanged(qint64 position);
  40. void onVolumeChanged(double volume);
  41. void onMutedChanged(bool muted);
  42. void onPlaybackSpeedChanged(double speed);
  43. void onErrorOccurred(const QString& error);
  44. void onStatsUpdated(const PlaybackStats& stats);
  45. private:
  46. void setupUI();
  47. void connectSignals();
  48. void updateUI();
  49. QString formatTime(qint64 microseconds);
  50. private:
  51. std::unique_ptr<PlayerAdapter> m_playerAdapter;
  52. VideoRenderer* m_videoRenderer;
  53. // UI组件
  54. QLabel* m_fileLabel;
  55. QLabel* m_stateLabel;
  56. QLabel* m_infoLabel;
  57. QLabel* m_timeLabel;
  58. QLabel* m_volumeLabel;
  59. QLabel* m_speedLabel;
  60. QLabel* m_statsLabel;
  61. QPushButton* m_openButton;
  62. QPushButton* m_playPauseButton;
  63. QPushButton* m_stopButton;
  64. QPushButton* m_muteButton;
  65. QSlider* m_positionSlider;
  66. QSlider* m_volumeSlider;
  67. QSlider* m_speedSlider;
  68. bool m_seeking = false;
  69. };
  70. #endif // SIMPLEPLAYERWINDOW_H