头文件:
#ifndef MEDIA_H
#define MEDIA_H
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
namespace Ui {
class Media;
}
class Media : public QMainWindow
{
Q_OBJECT
public:
explicit Media(QWidget *parent = 0);
~Media();
private:
Ui::Media *ui;
QLabel *label;
QProcess *process;
QWidget widget;
QPixmap pix;
QString file_name;
private slots:
void on_pushButton_5_clicked();
void on_kuaijin_clicked();
void on_pushButton_2_clicked();
void on_jinying_clicked();
void on_small_clicked();
void on_pushButton_clicked();
void on_pushButton_4_clicked();
void on_down_clicked();
void on_up_clicked();
void on_start_clicked();
void on_open_clicked();
};
#endif // MEDIA_H
主函数:
#include
#include "media.h"
#include
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QTextCodec::setCodecForTr(QTextCodec::codecForName("GBK"));
QTextCodec::setCodecForLocale(QTextCodec::codecForName("GBK"));
QTextCodec::setCodecForCStrings(QTextCodec::codecForName("GBK"));
Media w;
w.setDisabled(false);
w.setFixedSize(w.width(),w.height());
w.show();
return a.exec();
}
cpp函数:
#include "media.h"
#include "ui_media.h"
int i=0,j=0;
QString medialist[100];//存放播放的音频
QStringList::Iterator it;//迭代器
Media::Media(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::Media)
{
ui->setupUi(this);
/*************************************添加背景图片*************************************/
QImage image1;
image1.load(":/55.png"); //括号内为图片的相对目录
QImage image2 = image1.scaled(320,240);
QPalette palette;
palette.setBrush(this->backgroundRole(),QBrush(image2));
this->setPalette(palette);
process=new QProcess(this);
this->setWindowTitle(tr("播放器-----菜鸟营制作中心"));
this->setWindowIcon(QIcon("../../Media/100.png"));
}
Media::~Media()
{
delete ui;
}
/*************************************打开文件*************************************/
void Media::on_open_clicked()
{
int k=0;
QStringList list=QFileDialog::getOpenFileNames(this,"selecct media","/","*.*");
for(it=list.begin();it
}
/*************************************上一曲*************************************/
void Media::on_up_clicked()
{
process->close();
i++;
if(i>j)
i=0;
process->close();
QString path="../../Media/mplayer.exe";
QStringList list1;
list1<<"-slave";
list1<<"-quiet";
list1<<"-wid";//这两个不能分开写
list1<
}
/*************************************停止播放*************************************/
void Media::on_pushButton_4_clicked()
{
process->write("p\n");
}
/*************************************增大音量*************************************/
void Media::on_pushButton_clicked()
{
process->write("volume +1\n");
}
/*************************************减小音量*************************************/
void Media::on_small_clicked()
{
process->write("volume -1\n");
}
/*************************************开启静音*************************************/
void Media::on_jinying_clicked()
{
process->write(" mute 1\n");
}
/*************************************关闭静音*************************************/
void Media::on_pushButton_2_clicked()
{
process->write(" mute 0\n");
}
/*************************************快进*************************************/
void Media::on_kuaijin_clicked()
{
process->write("seek +1\n");
}
/*************************************快退*************************************/
void Media::on_pushButton_5_clicked()
{
process->write("seek -2\n");
}
效果图: