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

相关推荐
lw向北.1 小时前
Qt For Android之环境搭建(Qt 5.12.11 Qt下载SDK的处理方案)
android·开发语言·qt
小灰灰搞电子2 小时前
Qt实现Android的图案密码(图形解锁)源码分享
开发语言·qt
kiiila12 小时前
【Qt】对象树(生命周期管理)和字符集(cout打印乱码问题)
开发语言·qt
黄金右肾15 小时前
Qt之数据库使用(十四)
sql·qt·sqlite·database
杨德杰17 小时前
QT多媒体开发(一):概述
qt·音视频·多媒体
小王爱吃月亮糖17 小时前
QT开发【常用控件1】-Layouts & Spacers
开发语言·前端·c++·qt·visual studio
864记忆17 小时前
关于opencv、Qt、msvc编译器之间的关系
人工智能·qt·opencv
矛取矛求1 天前
QT的前景与互联网岗位发展
开发语言·qt
Leventure_轩先生1 天前
[WASAPI]从Qt MultipleMedia来看WASAPI
开发语言·qt
晓纪同学1 天前
QT-简单视觉框架代码
开发语言·qt