test_avplayer.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #include <QApplication>
  2. #include <QMainWindow>
  3. #include <QVBoxLayout>
  4. #include <QWidget>
  5. #include <QFileDialog>
  6. #include <QMenuBar>
  7. #include <QAction>
  8. #include <QMessageBox>
  9. #include "avplayerwidget.h"
  10. class TestMainWindow : public QMainWindow
  11. {
  12. Q_OBJECT
  13. public:
  14. TestMainWindow(QWidget *parent = nullptr)
  15. : QMainWindow(parent)
  16. {
  17. setupUI();
  18. setupMenus();
  19. }
  20. private slots:
  21. void openFile()
  22. {
  23. QString fileName = QFileDialog::getOpenFileName(this,
  24. tr("打开视频文件"), "",
  25. tr("视频文件 (*.mp4 *.avi *.mkv *.mov *.wmv *.flv *.webm);;所有文件 (*)"));
  26. if (!fileName.isEmpty()) {
  27. m_playerWidget->play(fileName);
  28. }
  29. }
  30. void showAbout()
  31. {
  32. QMessageBox::about(this, tr("关于"),
  33. tr("AVPlayer 测试程序\n\n"
  34. "这是一个基于Qt和FFmpeg的视频播放器测试程序。\n"
  35. "支持多种视频格式,使用OpenGL进行硬件加速渲染。"));
  36. }
  37. private:
  38. void setupUI()
  39. {
  40. m_playerWidget = new AVPlayerWidget(this);
  41. setCentralWidget(m_playerWidget);
  42. setWindowTitle(tr("AVPlayer 测试程序"));
  43. resize(800, 600);
  44. // 连接播放状态信号
  45. connect(m_playerWidget, &AVPlayerWidget::playStateChanged,
  46. this, [this](bool isPlaying) {
  47. QString title = isPlaying ?
  48. tr("AVPlayer 测试程序 - 播放中") :
  49. tr("AVPlayer 测试程序");
  50. setWindowTitle(title);
  51. });
  52. }
  53. void setupMenus()
  54. {
  55. // 文件菜单
  56. QMenu *fileMenu = menuBar()->addMenu(tr("文件(&F)"));
  57. QAction *openAction = new QAction(tr("打开文件(&O)"), this);
  58. openAction->setShortcut(QKeySequence::Open);
  59. connect(openAction, &QAction::triggered, this, &TestMainWindow::openFile);
  60. fileMenu->addAction(openAction);
  61. fileMenu->addSeparator();
  62. QAction *exitAction = new QAction(tr("退出(&X)"), this);
  63. exitAction->setShortcut(QKeySequence::Quit);
  64. connect(exitAction, &QAction::triggered, this, &QWidget::close);
  65. fileMenu->addAction(exitAction);
  66. // 帮助菜单
  67. QMenu *helpMenu = menuBar()->addMenu(tr("帮助(&H)"));
  68. QAction *aboutAction = new QAction(tr("关于(&A)"), this);
  69. connect(aboutAction, &QAction::triggered, this, &TestMainWindow::showAbout);
  70. helpMenu->addAction(aboutAction);
  71. }
  72. AVPlayerWidget *m_playerWidget;
  73. };
  74. int main(int argc, char *argv[])
  75. {
  76. QApplication app(argc, argv);
  77. app.setApplicationName("AVPlayer Test");
  78. app.setApplicationVersion("1.0");
  79. app.setOrganizationName("Test Organization");
  80. TestMainWindow window;
  81. window.show();
  82. return app.exec();
  83. }
  84. #include "test_avplayer.moc"