Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Playing Video in QML
QtWS25 Last Chance

Playing Video in QML

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 4 Posters 4.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Q Offline
    Q Offline
    QtRookie
    wrote on last edited by
    #1

    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{
    }
    

    }@

    1 Reply Last reply
    0
    • Q Offline
      Q Offline
      QtRookie
      wrote on last edited by
      #2

      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!

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mikealfa
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • D Offline
          D Offline
          dajansen
          wrote on last edited by
          #4

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

          QtQuick Quality Engineer / Lab Monkey
          Nokia Brisbane

          1 Reply Last reply
          0
          • B Offline
            B Offline
            bluestreak
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved