1、#include#include“mainwindow.h“#include“ui_mainwindow.h“PlayerClass:PlayerClass(QWidget *parent) :QMainWindow(parent),ui(newUi:PlayerClass) ui-setupUi(this);connect(this-ui-addBtn, SIGNAL(clicked(), this, SLOT(addFiles(); /链接connect(this-ui-playBtn, SIGNAL(clicked(), this, SLOT(playFile();connect(thi
2、s-ui-pauseBtn, SIGNAL(clicked(), this, SLOT(pauseFile();connect(this-ui-stopBtn,SIGNAL(clicked(), this, SLOT(stopFile();connect(this-ui-nextBtn, SIGNAL(clicked(), this, SLOT(nextFile();mediaObject = newPhonon:MediaObject(this);audioOutput= new Phonon:AudioOutput(this);Phonon:createPath(mediaObject,
3、audioOutput);/videoWidget = newPhonon:VideoWidget(this);/videoWidget-setAspectRatio(Phonon:VideoWidget:AspectRatioAuto);/videoWidget-setScaleMode(Phonon:VideoWidget:ScaleAndCrop);/Phonon:createPath(mediaObject, videoWidget);seekSlider = new Phonon:SeekSlider(this);seekSlider-setMediaObject(mediaObje
4、ct);this-ui-verticalLayout-addWidget(seekSlider); /*PlayerClass:PlayerClass()deleteui;void PlayerClass:changeEvent(QEvent *e) QMainWindow:changeEvent(e);switch (e-type() caseQEvent:LanguageChange:ui-retranslateUi(this);break;default:break;void PlayerClass:addFiles()QStringList files = QFileDialog:ge
5、tOpenFileNames(this, tr(“Select Files to play“);QString file;foreach(file, files)this-ui-listWidget-addItem(file);sourceList.append(file);void PlayerClass:playFile()if(sourceList.isEmpty()QMessageBox:information(this, tr(“no music files“), tr(“no files to play“);return;mediaObject-setQueue(sourceLis
6、t); /获取源文件,音频mediaObject-play(); /播放this-ui-playBtn-setEnabled(false); /当前的按钮为falsethis-ui-pauseBtn-setEnabled(true);void PlayerClass:pauseFile()mediaObject-pause();this-ui-pauseBtn-setEnabled(false);this-ui-playBtn-setEnabled(true);void PlayerClass:stopFile()mediaObject-stop();this-ui-pauseBtn-setEnabled(true);this-ui-playBtn-setEnabled(true);void PlayerClass:nextFile()int index= sourceList.indexOf(mediaObject-currentSource() + 1;if (sourceList.size() index) mediaObject-stop();mediaObject-setCurrentSource(sourceList.at(index);mediaObject-play();