我正在尝试使用ActiveQt在Qt(4.7.1)小部件中嵌入电影:
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);
...
输出:
Version Info: 12.0.7601.18741
Playing: C:\Users\qxf3567\Downloads\demoMedia\movie\earth.avi
State: 9
Duration: 00:00
我可以获得WMPlayer的版本号,但要播放的电影显示为0长度。这可能是什么问题?就好像它首先找不到文件一样?!