Playing Video in QML
-
I am able to play audio in QML without any errors or interruptions. However, when I wrote this code and tried to play video in QML, the video stops and program quits unexpectedly. Each time it starts running but at some point it crashes. Rarely it plays all the way until the end. When I play video in a Qt application it runs flawlessly but in QML it crashes. I also followed "this post":http://kunalmaemo.blogspot.com/2011/08/using-phonon-video-player-from-qml.html?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed:+blogspot/kunalmaemo+(Qt,+Maemo+and+other+stuff)# but the video crashes also. I believe that the additional class (widget.h) mentioned in the blog is not necessary. Here is my code:
QMLVIDEO.H
@#ifndef QMLVIDEO_H
#define QMLVIDEO_H#include <QtCore>
#include <phonon>
#include <QDeclarativeItem>
#include <QGraphicsProxyWidget>
#include <QWidget>class QmlVideo : public QDeclarativeItem
{Q_OBJECT
public:
explicit QmlVideo(QDeclarativeItem *parent = 0);
~QmlVideo();public slots:
private:
QGraphicsProxyWidget* proxy;
Phonon::VideoPlayer* player;
QWidget* myWidget;};
#endif // QMLVIDEO_H @
QMLVIDEO.CPP
@#include "qmlvideo.h"QmlVideo::QmlVideo(QDeclarativeItem *parent) :
QDeclarativeItem(parent)
{
myWidget = new QWidget();
player = new Phonon::VideoPlayer(Phonon::VideoCategory, myWidget);proxy = new QGraphicsProxyWidget(this); proxy->setWidget(myWidget); player->mediaObject()->setCurrentSource(Phonon::MediaSource("File Path")); player->play();
}
QmlVideo::~QmlVideo()
{
delete player;
delete proxy;
delete myWidget;
}@MAIN.CPP
@#include <QtGui/QApplication>
#include "qmlapplicationviewer.h"
#include "qmlvideo.h"
#include <QtDeclarative>Q_DECL_EXPORT int main(int argc, char *argv[])
{
QScopedPointer<QApplication> app(createApplication(argc, argv));qmlRegisterType<QmlVideo>("qmlVideo", 1, 0, "QmlVideo"); QmlApplicationViewer viewer; viewer.setOrientation(QmlApplicationViewer::ScreenOrientationAuto); viewer.setMainQmlFile(QLatin1String("qml/HybridNew/main.qml")); viewer.showExpanded(); return app->exec();
}@
MAIN.QML
@import QtQuick 1.0
import qmlVideo 1.0Rectangle {
width: 800
height: 800QmlVideo{ }
}@
-
QtRookie, did you ever get this to work? I am having trouble with the same code getting phonon to play the stream "v4l2://///dev/video2" (which it successfully displays in Qt) in QML