2012-08-07 63 views
1

我正在嘗試準備QML插件來以其他開發人員可以毫無麻煩地使用它的方式在嵌入式設備上播放視頻。然而,目前提出的方式幾乎總是需要在你的QML應用程序中編寫一些C++包裝器。我指的這個例子: http://gstreamer.freedesktop.org/data/doc/gstreamer/head/qt-gstreamer/html/examples_2qmlplayer_2main_8cpp-example.html插件中的QML和QtGStreamer

我希望能夠有插件,簡單的寫:

import AwesomeVideoPlugin 1.0 

Rect 
{ 
    AwesomeVideo 
    { 
     width: 320 
     height: 240 
     url: "./myvideo.avi" 
     // ... some minor stuff like mouse click handling, controls, etc. 
    } 
} 

目前QtGStreamer要求提供videoSurface財產VideoItem。唯一的方法是在rootContext()中爲附加屬性創建和設置上下文。並創建GraphicsVideoSurface我需要QGraphicsView(QDeclarativeView填充此角色)。

是否有可能:

  1. 獲取QDeclarativeView從內部QDeclarativeItem(對此我有QML插件只訪問)的方式,以後可以用來餵養GraphicsVideoSurface?我的猜測是沒有 - 但我找到了路徑QFraphicsItem :: scene()==>QGraphScene ==> QGraphScene :: views()==> QGraphicsView - 它看起來非常糟糕的編程,但也許有人知道它工作(我得到段錯誤)

  2. 是否有其他方式提供從QDeclarativeItem QtGStreamer視頻接收器?

格爾茨

Yatsa

回答

0

我有同樣的問題,但還沒有想出一個優雅的解決方案。

然而,一個想法是通過訪問器函數從子類QApplication對象中提供視頻表面。

這當然意味着您的插件依賴於具有getVideoSurface方法的應用程序子類,但它確實會從QML代碼中移除醜陋。

class MyApp : public QApplication 
{ 
    .... 
    QGst::Ui::GraphicsVideoSurface *getVideoSurface() { return m_videosurface; } 
} 

... 
int MyApp::init() 
{ 
    m_viewer = new QDeclarativeView(); 
    m_viewer->setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers))); 
    m_videosurface = new QGst::Ui::GraphicsVideoSurface(m_viewer); 
} 

MyVideoPlugin::MyVideoPlugin(QDeclarativeItem *parent) : QDeclarativeItem(parent) 
{ 
    QGst::Ui::GraphicsVideoSurface *surface = ((MyApp*)qApp)->getVideoSurface(); 
} 
... 

現在可以在不引用導出的視頻表面上下文項的情況下使用MyVideoPlugin元素。