1#include "videooutput.h"
2#include "mediaplayer.h"
7#include <QQmlComponent>
8#include <QGuiApplication>
12VideoOutput::VideoOutput(QQuickItem *parent)
15 , m_qmlContentComponent(nullptr)
20void VideoOutput::setSource(QObject *source)
22 if (m_source != source) {
23 if (m_source) disconnect(m_source, 0, this, 0);
26 Q_EMIT sourceChanged();
28 MediaPlayer* mediaPlayer = qobject_cast<MediaPlayer*>(source);
30 connect(mediaPlayer, &MediaPlayer::positionChanged, this, &VideoOutput::updateProperties);
31 connect(mediaPlayer, &MediaPlayer::playbackStateChanged, this, &VideoOutput::updateProperties);
32 connect(mediaPlayer->metaData(), SIGNAL(metaDataChanged()), this, SLOT(updateProperties()));
37void VideoOutput::itemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &value)
39 if (change == QQuickItem::ItemSceneChange && !m_qmlContentComponent) {
40 QWindowList list = QGuiApplication::topLevelWindows();
41 if (list.isEmpty()) return;
43 // The assumptions I make here really should hold.
44 QQuickView *quickView =
45 qobject_cast<QQuickView*>(list[0]);
47 m_qmlContentComponent = new QQmlComponent(quickView->engine(),
48 QString("%1/QtMultimedia/VideoSurface.qml").arg(mockPluginsDir()));
50 switch (m_qmlContentComponent->status()) {
51 case QQmlComponent::Ready:
52 createQmlContentItem();
54 case QQmlComponent::Loading:
55 connect(m_qmlContentComponent, &QQmlComponent::statusChanged,
56 this, &VideoOutput::onComponentStatusChanged);
58 case QQmlComponent::Error:
59 printComponentErrors();
60 qFatal("VideoOutput: failed to create content component.");
63 qFatal("VideoOutput: Unhandled component status");
66 QQuickItem::itemChange(change, value);
69void VideoOutput::printComponentErrors()
71 QList<QQmlError> errors = m_qmlContentComponent->errors();
72 for (int i = 0; i < errors.count(); ++i) {
73 qDebug() << errors[i];
77void VideoOutput::onComponentStatusChanged(QQmlComponent::Status status)
79 if (status == QQmlComponent::Ready) {
80 createQmlContentItem();
84void VideoOutput::createQmlContentItem()
86 m_qmlItem = qobject_cast<QQuickItem*>(m_qmlContentComponent->create());
87 m_qmlItem->setParentItem(this);
92void VideoOutput:: updateProperties()
94 if (!m_qmlItem) return;
96 MediaPlayer* mediaPlayer = qobject_cast<MediaPlayer*>(m_source);
97 if (!mediaPlayer) return;
99 QQmlProperty playbackStateProperty(m_qmlItem, "playbackState");
100 playbackStateProperty.write(QVariant::fromValue<int>(mediaPlayer->playbackState()));
102 QQmlProperty positionProperty(m_qmlItem, "position");
103 positionProperty.write(QVariant::fromValue(mediaPlayer->position()));
105 QQmlProperty propResSource(mediaPlayer->metaData(), "resolution");
106 QQmlProperty propResDest(m_qmlItem, "resolution");
108 if (propResSource.isValid() && propResDest.isValid()) {
109 propResDest.write(propResSource.read());
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list