qt调用mplayer

这篇博客介绍了如何在Qt应用程序中集成MPlayer,通过信号与槽机制响应按钮点击,加载指定路径的媒体文件,并利用定时器实现播放控制。内容涵盖Qt的信号与槽、文件路径操作及定时器应用。
摘要由CSDN通过智能技术生成
#ifndef MOVIEPLAY_H
#define MOVIEPLAY_H
#include <QPushButton>
#include <QWidget>
#include <QSlider>
#include <QListWidget>
#include <QListWidgetItem>
#include <QStringList>
#include <QString>
#include <QDir>
#include <QProcess>
#include <QTimer>
#include <QCloseEvent>
#include <QLabel>

class MoviePlay:public QWidget
{
	Q_OBJECT
public:
	QPushButton *play;
	QPushButton *stop;
	QPushButton *forward;
	QPushButton *rewind;

	QPushButton *come_back;
	QLabel *v_label;
	QLabel *list_label;	

	QProcess *mplayer;
	QStringList args;
	QSlider *volumeBar;
	QTimer *timer;
	QSlider *timeBar;
	QListWidget *listWidget;
	QDir *dir;
	QStringList *fileList;
	QString *file;
	
	/******************************************************************/
	QLabel *length;
	QLabel *curr;
	QPushButton *ok;
	/******************************************************************/

	int number;
	int status;
	int currentTime;
	int timeLength;
	int volume;
	MoviePlay(QWidget *parent=0);
	~MoviePlay();
	const QString deleteSuffix(const QString &str);

signals:
	void end();

public slots:
	void _play();
	void _stop();
	void _rewind();
	void _forward();
	void selectFile(QListWidgetItem * item);
	void playFinished(int,QProcess::ExitStatus);
	void parseOutput();
	void getCurrentTime();
	void setVolume(int);
	/******************************************************************/
	void _ok();
	/******************************************************************/
	void end_slot();
protected:
	void closeEvent(QCloseEvent *e);
};
#endif

以上是头文件里面都文件里面类的定义


下面是具体实现


#include "musicplay.h"
#include <QString>
#include <iostream>

const QString DIR = "/home/music";
//const QString DIR = "/root/all_show/music";
const QString ICON = "/home/app.png";
//const QString ICON = "/root/all_show/music/app.png";
const QString PATH = "/home/mplayer";
//const QString PATH = "/usr/local/mplayer/bin/mplayer";
const int MAX_VOLUME = 25;
const int WIDTH = 320;
const int HEIGHT = 240;
const int BUTTON_WIDTH = 40;
const int BUTTON_HEIGHT = 40;
MusicPlay::MusicPlay(QWidget *parent)
	:QWidget(parent)
{
	status = 0;
	row = 2;
	mode = 1;	
	volume = 25;
	nextEnable = false;
	
	this->resize(WIDTH,HEIGHT);
	path = new QString(PATH);
	args<<"-slave"<<"-quiet"<<"-ac"<<"mad";

	mplayer = new QProcess(this);
	connect(mplayer,SIGNAL(readyReadStandardOutput()),this,SLOT(parseOutput()));
	
	timer = new QTimer(this);
	connect(timer,SIGNAL(timeout()),this,SLOT(getCurrentTime()));
	
	modeComboBox =
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值