3
votes

I'm trying to play test video with qml by this code:

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()
    }
}

But, when I click on view, nothing happens. And if I change onPressed event to something else action (not with the player), it works fine, then it's not a MouseArea problem.

Where did I wrong?

Thank you.

2
How do you run your QML file? Do you user qmlscene or did you create a QML project including a main.cpp?Simon Warta

2 Answers

3
votes

The file path seems to be wrong. Since baclslashes need to be escaped in string litterals, the actual path remaining is:

c:\Downloads\video.mp4

That's a path, but not an URL. The correct URL is (see File URIs in Windows):

file:///C:/Downloads/video.mp4
0
votes

On your code source:

C:\\Downloads\\video.mp4 

should be source:

C://Downloads//video.mp4