You have to extend QMediaPlayer.
Look at this from qdeclarativevideooutput.cpp source code:
/*
\qmlproperty variant QtMultimedia::VideoOutput::source
This property holds the source item providing the video frames like MediaPlayer or Camera.
If you are extending your own C++ classes to interoperate with VideoOutput, you can either provide a QObject based class with a \c mediaObject property that exposes a QMediaObject derived class that has a QVideoRendererControl available, or you can provide a QObject based class with a writable \c videoSurface property that can accept a QAbstractVideoSurface based class and can follow the correct protocol to deliver QVideoFrames to it.
*/
So, if you do like this:
MyMediaPlayer.h
#include <QMediaPlayer>
class MyMediaPlayer: public QMediaPlayer
{
Q_OBJECT
Q_PROPERTY(QAbstractVideoSurface* videoSurface READ getVideoSurface WRITE setVideoSurface )
public:
MyMediaPlayer(QObject * parent = 0, Flags flags = 0);
public slots:
void setVideoSurface(QAbstractVideoSurface *surface);
QAbstractVideoSurface* getVideoSurface();
private:
QAbstractVideoSurface* m_surface;
};
MyMediaPlayer.cpp
#include "MyMediaPlayer.h"
MyMediaPlayer::MyMediaPlayer(QObject* parent, Flags flags): QMediaPlayer(parent, flags)
{
}
void MyMediaPlayer::setVideoSurface(QAbstractVideoSurface* surface)
{
qDebug() << "Changing surface";
m_surface = surface;
setVideoOutput(m_surface);
}
QAbstractVideoSurface* MyMediaPlayer::getVideoSurface()
{
return m_surface;
}
then:
MyMediaPlayer* player = new MyMediaPlayer();
QQuickView view;
view.engine()->rootContext()->setContextProperty("mediaplayer", player);
your qml:
VideoOutput {
id: videooutput
width: 320
height: 240
source: mediaplayer
}
It works. I’ve just tested it with Qt 5.2
↧