QTplayer 程序

#ifndef MAINWINDOW_H

#define MAINWINDOW_H

#include <QMainWindow>

#include <QProcess>

#include <QTimer>

QT_BEGIN_NAMESPACE

namespace Ui { class MainWindow; }

QT_END_NAMESPACE

class MainWindow : public QMainWindow

{

Q_OBJECT

public:

MainWindow(QWidget *parent = nullptr);

~MainWindow();

private slots:

//void btnFileOpen_clicked();

void on_btnFileOpen_clicked();

void on_btnPlay_clicked();

void on_btnPrevious_clicked();

void on_btnNext_clicked();

void on_dialVoice_valueChanged(int value);

void on_horizontalSlider_valueChanged(int value);

void doProcessTimeOut();

private:

Ui::MainWindow *ui;

QStringList playList;

int playIndex;

QProcess *playProcess;

int isPlaying;

QTimer *myTimer;

void Init();

void playMovie(const QString filename);

};

#endif // MAINWINDOW_H


#include "mainwindow.h"

#include "ui_mainwindow.h"

#include "QFileDialog"

MainWindow::MainWindow(QWidget *parent)

: QMainWindow(parent)

, ui(new Ui::MainWindow)

{

ui->setupUi(this);

Init();

//connect(ui->btnFileOpen,&QPushButton::clicked,this,&MainWindow::btnFileOpen_clicked);

}

MainWindow::~MainWindow()

{

delete ui;

}

//slots

//void MainWindow::btnFileOpen_clicked()

//{

// QStringList array = QFileDialog::getOpenFileNames(this,"add videos","/home/l/Videos","video(*.mp4)");

// if (array.length() <=0) return;

// playList = array;

// playIndex = 0;

// playMovie(playList.at(playIndex));

//}

void MainWindow::on_btnFileOpen_clicked()

{

QStringList array = QFileDialog::getOpenFileNames(this,"add videos","/home/l/Videos","video(*.mp4)");

if (array.length() <=0) return;

playList = array;

playIndex = 0;

playMovie(playList.at(playIndex));

}

void MainWindow::on_btnPlay_clicked()

{

QString cmd = "pause\n";

switch (isPlaying)

{

case 0:

break;

case 1:

isPlaying = 2;

playProcess->write(cmd.toLatin1());

ui->btnPlay->setIcon(QIcon(":/new/prefix1/image/icons-start.png"));

break;

case 2:

isPlaying = 1;

playProcess->write(cmd.toLatin1());

ui->btnPlay->setIcon(QIcon(":/new/prefix1/image/stop.png"));

break;

}

}

void MainWindow::on_btnPrevious_clicked()

{

playIndex--;

if (playIndex < 0)

{

playIndex = playList.length() -1;

}

playMovie(playList.at(playIndex));

}

void MainWindow::on_btnNext_clicked()

{

playIndex++;

if (playIndex >= playList.length())

{

playIndex = 0;

}

playMovie(playList.at(playIndex));

}

void MainWindow::on_dialVoice_valueChanged(int value)

{

if (isPlaying != 0)

{

QString cmd = QString("volume %1 1\n").arg(value);

playProcess->write(cmd.toLatin1());

}

}

void MainWindow::on_horizontalSlider_valueChanged(int value)

{

if (isPlaying != 0)

{

QString cmd = QString("seek %1 1\n").arg(value);

playProcess->write(cmd.toLatin1());

}

}

void MainWindow::doProcessTimeOut()

{

QString cmd = "get_percent_pos\n";

playProcess->write(cmd.toLatin1());

}

//end slots

//function

void MainWindow::Init()

{

playList.clear();

playIndex=0;

playProcess = new QProcess(this);

isPlaying = 0;

myTimer = new QTimer(this);

connect(myTimer,&QTimer::timeout,this,&MainWindow::doProcessTimeOut);

}

void MainWindow::playMovie(const QString filename)

{

QString program = "/usr/bin/mplayer";

QStringList arguments;

arguments << filename;

arguments << "-slave";

arguments << "-quiet";

arguments << "-wid";

arguments << QString::number(ui->label->winId());

playProcess->close();

playProcess->start(program,arguments);

myTimer->start(1000*1);

isPlaying = 1;

ui->btnPlay->setIcon(QIcon(":/new/prefix1/image/stop.png"));

QString cmd = QString("volume %1 1\n").arg(ui->dialVoice->value());

playProcess->write(cmd.toLatin1());

ui->horizontalSlider->setValue(0);

}

//end function

相关推荐
沫璃染墨6 小时前
《Qt从零入门系列(十三):QSS样式表详解——从选择器与层叠规则到控件美化实战》
开发语言·css·c++·qt·ui·qt6.3·qss
好好学习O(∩_∩)O11 小时前
[QT] 多线程moveToThread 和易踩的8个坑
开发语言·qt
北i13 小时前
Dubbo 默认超时重试:把下游打雪崩的隐形放大器
开发语言·qt·dubbo
扶尔魔ocy15 小时前
【qt openGL入门笔记】OSG实现显示飞机模型飞行的点迹(二)
qt·opengl·osg
Python图像识别18 小时前
43-【2027毕设】YOLO11暴力检测识别系统 - Python完整源码+PyQt5界面+训练模型+数据集
python·qt·课程设计
bug和崩溃我都要1 天前
QT 开发的专业截图录屏工具 - macOS版 / Windows版
windows·qt·mac·录屏·截屏
Python图像识别1 天前
40-【2027毕设】YOLO11面部口罩检测识别系统 - Python完整源码+PyQt5界面+训练模型+数据集
python·qt·课程设计
Python图像识别1 天前
39-【2027毕设】YOLO11行人摔倒检测系统 - Python完整源码+PyQt5界面+训练模型+数据集
python·qt·课程设计
Quz2 天前
QML PathView:直线路径与曲线路径
qt·动画·qml
扶尔魔ocy2 天前
【qt openGL入门笔记】OSG实现飞机模型在网格图上飞行
qt·opengl·osg