1. create a new Qt project with module Phonon
...
2. Add some codes in mainwindow.h & mainwindow.cpp
--- mainwindow.h ---
class MainWindow : public QMainWindow {
:
private:
Ui::MainWindow *ui;
QString m_mediaFile;
Phonon::VideoPlayer *player;
};
--- mainwindow.cpp ---
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); player = new Phonon::VideoPlayer(Phonon::VideoCategory, this); /// TODO: shall be a smart way to resize the playback area player->move(0,63); player->resize(width(), height()-63); } void MainWindow::on_action_Open_triggered() { QStringList filters; filters << "Image files (*.mpg *.avi)" << "Any files (*)"; QFileDialog dialog(this); dialog.setNameFilters(filters); if (dialog.exec()) { QStringList fileNames; fileNames = dialog.selectedFiles(); m_mediaFile = fileNames.at(0); setWindowTitle(m_mediaFile); /// Load media file. player->load(Phonon::MediaSource(m_mediaFile)); player->play(); } }
...
The simple program can play video, mp3 and jpeg.
[] video : rmvb, mpg, vob ...
[] image : jpg ...[] music : mp3 ...