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&#40;QLatin1String("qml/HybridNew/main.qml"&#41;);
    viewer.showExpanded();
    
    return app->exec&#40;&#41;;
    

    }@

    MAIN.QML
    @import QtQuick 1.0
    import qmlVideo 1.0

    Rectangle {
    width: 800
    height: 800

    QmlVideo{
    }
    

    }@



  • I also tried several other examples of working code for implementing phonon video in QML but it seems that while it works for other people it crashes on my computer for no clear reason!



  • hey...hello...
    can u please post the code for playing audio, which u mentioned u have successfully implemented and explain a lil bit ?



  • Any chance of a backtrace? I tried it, works ok for me.



  • 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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.