Controlling Windows Media Player 12 with Qt / ActiveQt

591 Views Asked by At

I am trying to embed a movie in a Qt (4.7.1) widget using ActiveQt:

VideoManager2.h:

    #ifndef VIDEOMANAGER2_H_
    #define VIDEOMANAGER2_H_

    #include <QtCore/QtCore>
    #include <QtGui/QtGui>
    #include "qaxwidget.h"

    class VideoManager2: public QWidget{
        Q_OBJECT
        //Q_ENUMS(ReadyStateConstants);


        enum PlayStateConstants { Stopped = 0, Paused = 1, Playing = 2 };
        enum ReadyStateConstants { Uninitialized = 0, Loading = 1, Interactive = 3, Complete = 4 };

        QAxWidget *wmp;

    private slots:  
         void onPlayStateChange(int a, int b);
         void onReadyStateChange(ReadyStateConstants readyState);

    public:
        VideoManager2();
    };

    #endif /* VIDEOMANAGER2_H_ */

VideoManager2.cpp:

    #include <QtCore/QtCore>
    #include <QtGui/QtGui>
    #include <InitGuid.h>
    #include "VideoManager2.h"
    #include "wmp.h"
    #include "qaxobject.h"

    VideoManager2::VideoManager2() {

        wmp = new QAxWidget(this);
        wmp->setControl("{6BF52A52-394A-11D3-B153-00C04F79FAA6}");

        wmp->setProperty("ShowControls", false);
        wmp->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);

        wmp->setProperty("URL", "C:/Users/qxf3567/Downloads/demoMedia/movie/earth.avi");
        qDebug("Version Info: %s", qPrintable(wmp->property("versionInfo").toString()));
        qDebug("Playing: %s", qPrintable(wmp->property("URL").toString()));
        qDebug("State: %s", qPrintable(wmp->property("playState").toString()));

        QAxObject* currentMedia= wmp->querySubObject("currentMedia");
        IWMPMedia *media;
        currentMedia->queryInterface(QUuid(__uuidof(IWMPMedia)), (void **)&media);


        {
            BSTR durationStr;
            media->get_durationString(&durationStr);
            QString convertedBSTR((QChar*) durationStr, wcslen(durationStr));
            qDebug("Duration: %s", qPrintable(QString(convertedBSTR)));

        }

    }

     void VideoManager2::onPlayStateChange(int a, int b){
     }
     void VideoManager2::onReadyStateChange(ReadyStateConstants readyState){
     }

main.cpp:

    ...
    QScrollArea *movieWidget = new QScrollArea(groupBox_2);
    VideoManager2 vm;
    ui->movieWidget->setWidget(&vm);
    ...

Output:

    Version Info: 12.0.7601.18741
    Playing: C:\Users\qxf3567\Downloads\demoMedia\movie\earth.avi
    State: 9
    Duration: 00:00

I can get the Version number of WMPlayer, but the movie to be played is displayed as 0 length. What could be the problem here? It's as if it doensn't find the file in the first place?!

0

There are 0 best solutions below