PDA

View Full Version : MediaPlayer: duration of 0 for non-streaming video



Urthas
29th July 2015, 16:53
Hello,

Consider the following main.qml code, which works perfectly:


import QtQuick 2.4
import QtQuick.Controls 1.3
import QtQuick.Window 2.2
import QtMultimedia 5.0

ApplicationWindow {
title: qsTr("Hello Video")
width: 640
height: 480
visible: true

Video {
id: video

source: "file:///path/to/cuteLionVideo.mp4"
anchors.fill: parent
}

MouseArea {
id: playArea

anchors.fill: parent

onPressed: {
console.debug("Found video with duration: " + video.duration)
video.play();
}
}
}

The duration prints correctly, and all is well. Now consider the following, in which the source is not bound, but assigned on the fly:


ApplicationWindow {
Video {
id: video

anchors.fill: parent
}

MouseArea {
id: playArea

anchors.fill: parent

onPressed: {
video.source = "file:///path/to/cuteLionVideo.mp4"
console.debug("Found video with duration: " + video.duration)
video.play();
}
}
}

The duration prints 0. The documentation for the duration property states that:


If the media doesn't have a fixed duration (a live stream for example) this will be 0.

So it would seem that the video file in the above code is considered not to have a fixed duration. But in the first snippet, where the source was bound, it was correctly considered to have a fixed duration. Something must have happened under the hood in that case. My question is whether it is possible to emulate that "something" so that assigning a file URL to source at run-time leads to the desired duration behavior?

Thank you.