Created
August 16, 2010 12:05
-
-
Save torarnv/526849 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ###################################################################### | |
| # Automatically generated by qmake (2.01a) man. aug. 16 11:59:15 2010 | |
| ###################################################################### | |
| TEMPLATE = app | |
| TARGET = | |
| DEPENDPATH += . | |
| INCLUDEPATH += . | |
| CONFIG += opengl | |
| CONFIG *= mobility | |
| MOBILITY += multimedia | |
| # Input | |
| SOURCES += main.cpp | |
| ----------------------------- >8 ----------------------------------- | |
| #include <QtGui> | |
| #include <QMediaPlayer> | |
| #include <QVideoWidget> | |
| #include <QGraphicsVideoItem> | |
| #include <QGLWidget> | |
| class VideoItem : public QGraphicsVideoItem | |
| { | |
| public: | |
| VideoItem(QMediaPlayer* player) : QGraphicsVideoItem(), m_player(player) {} | |
| protected: | |
| void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) { | |
| QGraphicsVideoItem::paint(painter, option, widget); | |
| if (m_player) { | |
| m_player->setVideoOutput(this); | |
| m_player = 0; | |
| } | |
| } | |
| QMediaPlayer* m_player; | |
| }; | |
| class GraphicsView : public QGraphicsView | |
| { | |
| Q_OBJECT | |
| public: | |
| GraphicsView() : QGraphicsView(), m_player(new QMediaPlayer), m_videoItem(0) { | |
| QGraphicsScene* scene = new QGraphicsScene(this); | |
| setScene(scene); | |
| setViewport(new QGLWidget); | |
| setGeometry(QApplication::desktop()->screenGeometry()); | |
| setSource(); | |
| setNormalItem(); | |
| m_player->play(); | |
| } | |
| ~GraphicsView() { delete m_player; } | |
| public slots: | |
| void setSource() { | |
| m_player->setMedia(QUrl("http://chaos.troll.no/~tavestbo/webkit/mediaelement/micmacs.sd.m4v")); | |
| } | |
| void setNormalItem() { | |
| delete m_videoItem; | |
| m_videoItem = new QGraphicsVideoItem; | |
| scene()->clear(); | |
| scene()->addItem(m_videoItem); | |
| m_videoItem->setPos(QPointF(0, 0)); | |
| m_videoItem->setSize(QApplication::desktop()->screenGeometry().size()); | |
| // The following line will cause a call to QPainterVideoSurface::createPainter(), | |
| // but since the item has not recived a paint-event yet, no GL context has been | |
| // set on the surface. Result: QVideoSurfaceCoreGraphicsPainter(glSupported=false) | |
| m_player->setVideoOutput(m_videoItem); | |
| } | |
| void setCustomItem() { | |
| delete m_videoItem; | |
| m_videoItem = new VideoItem(m_player); | |
| scene()->clear(); | |
| scene()->addItem(m_videoItem); | |
| m_videoItem->setPos(QPointF(0, 0)); | |
| m_videoItem->setSize(QApplication::desktop()->screenGeometry().size()); | |
| // This will defer the setVideoOutput() call until after the first paint | |
| } | |
| public: | |
| QMediaPlayer* m_player; | |
| QGraphicsVideoItem* m_videoItem; | |
| }; | |
| int main(int argc, char** argv) | |
| { | |
| QApplication app(argc, argv); | |
| GraphicsView video; | |
| video.show(); | |
| QWidget *window = new QWidget; | |
| QHBoxLayout *layout = new QHBoxLayout; | |
| window->setLayout(layout); | |
| QPushButton* button; | |
| /* | |
| button = new QPushButton("play"); | |
| QObject::connect(button, SIGNAL(clicked()), video.m_player, SLOT(play())); | |
| layout->addWidget(button); | |
| button = new QPushButton("pause"); | |
| QObject::connect(button, SIGNAL(clicked()), video.m_player, SLOT(pause())); | |
| layout->addWidget(button); | |
| button = new QPushButton("reload source"); | |
| QObject::connect(button, SIGNAL(clicked()), &video, SLOT(setSource())); | |
| layout->addWidget(button); | |
| */ | |
| button = new QPushButton("reload item (normal)"); | |
| QObject::connect(button, SIGNAL(clicked()), &video, SLOT(setNormalItem())); | |
| layout->addWidget(button); | |
| button = new QPushButton("reload item (custom)"); | |
| QObject::connect(button, SIGNAL(clicked()), &video, SLOT(setCustomItem())); | |
| layout->addWidget(button); | |
| window->show(); | |
| return app.exec(); | |
| } | |
| #include "main.moc" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment