123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- #include "mainwindow.h"
- #include "ui_mainwindow.h"
- #include <QFileDialog>
- MainWindow::MainWindow(QWidget *parent)
- : QMainWindow(parent)
- , ui(new Ui::MainWindow)
- {
- ui->setupUi(this);
- this->setWindowTitle(QString("Qt+ffmpeg视频播放(硬解码)"));
- m_playImages.append(ui->widget);
- m_playImages.append(ui->widget_3);
- m_playImages.append(ui->widget_4);
- m_playImages.append(ui->widget_5);
- m_playImages.append(ui->widget_6);
- m_playImages.append(ui->widget_7);
- for(int i = 0; i < m_playImages.count(); i++)
- {
- m_readThreads.append(new ReadThread);
- connect(m_readThreads.at(i), &ReadThread::updateImage, m_playImages.at(i), &PlayImage::updateImage); // 这里使用Qt::DirectConnection会大幅度降低性能
- }
- connect(m_readThreads.at(0), &ReadThread::playState, this, &MainWindow::on_playState);
- }
- MainWindow::~MainWindow()
- {
- delete ui;
- }
- /**
- * @brief 获取本地视频路径
- */
- void MainWindow::on_btn_file_clicked()
- {
- QString strName = QFileDialog::getOpenFileName(this, "选择播放视频~!", "/", "视频 (*.mp4 *.m4v *.mov *.avi *.flv);; 其它(*)");
- if(strName.isEmpty())
- {
- return;
- }
- ui->com_url->setCurrentText(strName);
- }
- /**
- * @brief 视频播放/停止
- */
- void MainWindow::on_btn_start_clicked()
- {
- if(ui->btn_start->text() == "开始播放")
- {
- for(int i = 0; i < m_readThreads.count(); i++)
- {
- m_readThreads.at(i)->setHWDecoder(ui->check_HW->isChecked());
- m_readThreads.at(0)->open("C:/Users/admin/Desktop/原文件/1.2023年度大事记.mp4");
- m_readThreads.at(1)->open("C:/Users/admin/Desktop/原文件/2.赵.mp4");
- m_readThreads.at(2)->open("https://www.douyu.com/96291?dyshid=1937d4e1-3332100244c16a702808d75e00031701&dyshci=1");
- }
- }
- else
- {
- for(int i = 0; i < m_readThreads.count(); i++)
- {
- m_readThreads.at(i)->close();
- }
- }
- }
- /**
- * @brief 视频暂停/继续
- */
- void MainWindow::on_btn_pause_clicked()
- {
- if(ui->btn_pause->text() == "暂停")
- {
- for(int i = 0; i < m_readThreads.count(); i++)
- {
- m_readThreads.at(i)->pause(true);
- }
- ui->btn_pause->setText("继续");
- }
- else
- {
- for(int i = 0; i < m_readThreads.count(); i++)
- {
- m_readThreads.at(i)->pause(false);
- }
- ui->btn_pause->setText("暂停");
- }
- }
- /**
- * @brief 根据视频播放状态切换界面设置
- * @param state
- */
- void MainWindow::on_playState(ReadThread::PlayState state)
- {
- if(state == ReadThread::play)
- {
- this->setWindowTitle(QString("正在播放:%1").arg(m_readThreads.at(0)->url()));
- ui->btn_start->setText("停止播放");
- }
- else
- {
- ui->btn_start->setText("开始播放");
- ui->btn_pause->setText("暂停");
- this->setWindowTitle(QString("Qt+ffmpeg视频播放(硬解码)"));
- }
- }
|