PDA

View Full Version : Video Avi and QT



eltecprogetti
16th April 2012, 08:59
Hi,
I tried to play a vedeo Avi in Windows XP using QT4.

My code is very simple:

QString fileName = QFileDialog::getOpenFileName(this, tr("Open Movie"), QDir::homePath(), NULL);
Phonon::VideoPlayer *player = new Phonon::VideoPlayer(Phonon::VideoCategory, ui->graphicsView);
player->play(fileName);

I have no errors, but starting the program nothing happens, the graphicsView remains empty and the video does not start.

On Windows XP I loaded the video codec, in fact the video start normally using any video player.

amleto
16th April 2012, 09:33
answered elsewhere (http://www.qtforum.org/article/37747/video-avi-and-qt.html)

eltecprogetti
16th April 2012, 09:52
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QFileDialog>
#include <Phonon/VideoPlayer>

MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}

MainWindow::~MainWindow()
{
delete ui;
}

void MainWindow::on_pushButton_clicked()
{

QString fileName = QFileDialog::getOpenFileName(this, tr("Open Movie"), QDir::homePath(), NULL);
Phonon::VideoPlayer *player = new Phonon::VideoPlayer(Phonon::VideoCategory, ui->graphicsView);
player->play(fileName);

}



I have only a pushbutton and a graphicswiev in the designer mainwindow.ui

amleto
16th April 2012, 10:59
yes, thats the problem.

(just because you make a parent doesnt mean graphics will show there.)

eltecprogetti
16th April 2012, 11:23
so how do I do to watch the video?

amleto
16th April 2012, 11:26
didn't I show you this already?
http://qt-project.org/doc/qt-4.8/phonon-videoplayer.html#videoWidgetx

eltecprogetti
16th April 2012, 11:41
This is the example on the page that you linked:


VideoPlayer *player = new VideoPlayer(Phonon::VideoCategory, parentWidget);
connect(player, SIGNAL(finished()), player, SLOT(deleteLater()));
player->play(url);

I don't see difference between this example and my code, except the parentWidget. If I write in my code "parentWidget" I have an error:
C3867: 'QWidget::parentWidget': function call missing argument list; use '&QWidget::parentWidget' to create a pointer to member

I do not understand the error and I do not know what to do. What it means "use '&QWidget::parentWidget' to create a pointer to member"?

amleto
16th April 2012, 11:55
QString fileName = QFileDialog::getOpenFileName(this, tr("Open Movie"), QDir::homePath(), NULL);
Phonon::VideoPlayer *player = new Phonon::VideoPlayer(Phonon::VideoCategory, ui->graphicsView);
player->play(fileName);

player->videoWidget()->show();


I think you need to learn some basics of Qt and go though some tutorials

eltecprogetti
16th April 2012, 12:14
You're right, I need to learn the basics of QT, because I always worked until a few days ago on VB6.
Anyway I tried your code and not change anything, I do not see anything yet ....

wysota
16th April 2012, 12:31
If you want to show a video on a graphics view then you need to create a graphics item that you will put into the view. You are not creating a regular widget and putting it in the graphics view widget, probably under the viewport() of the view which is why you can't see anything. First of all pass null as the parent widget and see if the video works at all. If not, then you have some problem with Phonon. If it does, then have a look at the Video Graphics Item Example.

eltecprogetti
16th April 2012, 12:49
I passed null as the parent widget, but it don't change anything. I have some problem with Phonon.

I tried the example "Video Graphics Item Example", but this code is only for animated gif and bmg video, not for avi.

wysota
16th April 2012, 14:35
I passed null as the parent widget, but it don't change anything.
Completely no change? Are you sure you rebuilt your project? At worst you should have gotten a new empty window.


I tried the example "Video Graphics Item Example", but this code is only for animated gif and bmg video, not for avi.
And the difference is...?

eltecprogetti
16th April 2012, 14:59
I rebuilt my project and I have not a empty window. I see only a empty form with a empty graphics view.

In the example linked from you, before to open the dialog box "Open Movie...", all the supported format are loaded:

QStringList supportedFormats;
foreach (QString fmt, QMovie::supportedFormats())
supportedFormats << fmt;
foreach (QString fmt, QImageReader::supportedImageFormats())
supportedFormats << fmt;


So I can't play avi files because its are not supported; only gif and bmg are supported....


ps. I don't use tags for the code because I don't know these tags.

wysota
16th April 2012, 15:22
I rebuilt my project and I have not a empty window. I see only a empty form with a empty graphics view.
Please provide a minimal compilable example reproducing this behaviour.

eltecprogetti
16th April 2012, 15:40
Resolved !!!!

I forgot the:

player->show();