Hello,

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

Qt Code:
  1. import QtQuick 2.4
  2. import QtQuick.Controls 1.3
  3. import QtQuick.Window 2.2
  4. import QtMultimedia 5.0
  5.  
  6. ApplicationWindow {
  7. title: qsTr("Hello Video")
  8. width: 640
  9. height: 480
  10. visible: true
  11.  
  12. Video {
  13. id: video
  14.  
  15. source: "file:///path/to/cuteLionVideo.mp4"
  16. anchors.fill: parent
  17. }
  18.  
  19. MouseArea {
  20. id: playArea
  21.  
  22. anchors.fill: parent
  23.  
  24. onPressed: {
  25. console.debug("Found video with duration: " + video.duration)
  26. video.play();
  27. }
  28. }
  29. }
To copy to clipboard, switch view to plain text mode 

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

Qt Code:
  1. ApplicationWindow {
  2. Video {
  3. id: video
  4.  
  5. anchors.fill: parent
  6. }
  7.  
  8. MouseArea {
  9. id: playArea
  10.  
  11. anchors.fill: parent
  12.  
  13. onPressed: {
  14. video.source = "file:///path/to/cuteLionVideo.mp4"
  15. console.debug("Found video with duration: " + video.duration)
  16. video.play();
  17. }
  18. }
  19. }
To copy to clipboard, switch view to plain text mode 

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.