顯示具有 Qt 標籤的文章。 顯示所有文章
顯示具有 Qt 標籤的文章。 顯示所有文章

2010/05/21

Qt - phonon

VideoPlayback in Qt via Phonon

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 ...

2009/04/30

3 Qt Exercises After 1 Week Classess

After one week classes, we are asked to write some codes.

 1. Something like ping-pong. >> (2 buttons are used, one as ball and another as board).  



 2. A simple painter. >> Undo

 3. An address book records some basic information. >> Open/Save/Insert/Delete/Head/Prev/Next/Tail
 

 It's a pity that I don't have time to improve them at this moment. Because more other lessons are there.