首页 文章

为什么QML MediaPlayer / VideoOutput对我不起作用?

提问于
浏览
3

我试图用这段代码用qml播放测试视频:

import QtQuick 2.2
import QtMultimedia 5.0

Item {
    width: 300
    height: 300

    MediaPlayer {
        id: player
        source: "C:\\Downloads\\video.mp4"
    }

    VideoOutput {
        id: video
        anchors.fill: parent
        source: player
    }

    MouseArea {
        anchors.fill: parent
        onPressed: player.play()
    }
}

但是,当我点击视图时,没有任何反应 . 如果我将 onPressed 事件更改为其他操作(不是 player ),它可以正常工作,那么它不是 MouseArea 问题 .

我哪里错了?

谢谢 .

2 回答

  • 0

    文件路径似乎是错误的 . 由于baclslashes需要在字符串litterals中转义,实际的剩余路径是:

    c:\Downloads\video.mp4
    

    这是一条路径,但不是URL . 正确的URL是(见File URIs in Windows):

    file:///C:/Downloads/video.mp4
    
  • 3

    在您的代码源上:

    C:\\Downloads\\video.mp4
    

    应该是来源:

    C://Downloads//video.mp4
    

相关问题