2013-09-05 43 views
0

我想在qt快速應用程序的背景下從網絡攝像頭呈現視頻。 我用這個代碼5.1.1的文件來渲染測試視頻:使用QtQuick進行視頻播放

import QtQuick 2.0 
    import QtMultimedia 5.0 

    Item { 
     MediaPlayer { 
      id: mediaplayer 
      source: "groovy_video.mp4" 
     } 

     VideoOutput { 
      anchors: parent.fill 
      source: mediaplayer 
     } 

     MouseArea { 
      id: playArea 
      anchors.fill: parent 
      onPressed: mediaplayer.play(); 
     } 
    } 

我沒有QtQuick經驗,如果連的例子(未修改)工作是雙萬分:

Invalid property assignment: "anchors" is a read-only property 
anchors: parent.fill 

什麼是錯的?

+1

它的錯誤與文檔,正確的語法都沒有 「錨:parent.fill」,而是 「anchors.fill:父」(如在鼠標區域)。哪一頁文件?爲了修復它 – gbdivers

+0

@Guillaume Belz here http://qt-project.org/doc/qt-5.0/qtmultimedia/qml-qtmultimedia5-mediaplayer.html – iMath

回答

0

這可能會解決它:

import QtQuick 2.0 
import QtMultimedia 5.0 

Item { 
    height: video.implicitHeight // or video.height 
    width: video.implicitWidth // or video.width 
    MediaPlayer { 
     id: mediaplayer 
     source: "groovy_video.mp4" 
    } 

    VideoOutput { 
     id: video 
     source: mediaplayer 
    } 

    MouseArea { 
     id: playArea 
     anchors.fill: parent 
     onPressed: mediaplayer.play(); 
    } 
}