QML Video onSourceChanged
-
Hi,
I'm running a Video component as a view's background. I have 4 different video files for 4 different device types/screen aspect ratios. Tablet_Landscape, Tablet_Portrait, Phone_Landscape and Phone_Portrait.
I'm creating a binding on the orientation to switch between the Landscape and Portrait videos for the source but I noticed that when changing the orientation the video just disappears. I do get an onSourceChanged event but the new video is not actually loaded. I've looked through the documentation and there's nothing about this. Is there something I should call to load the new source onSourceChanged and start playback or is that simply a limitation of the Video component? There's a workaround with Loaders or possibly Playlists, but I'd rather just use a Source binding as it's just more elegant.
My code:
Video { id: requirementsScreenId anchors.fill: root source: { if (isPhone()) { if (orientation === "landscape") return "qrc:/Images/Phone_Landscape.mp4" else return "qrc:/Images/Phone_Portrait.mp4" } else { if (orientation === "landscape") return "qrc:/Images/Tablet_Landscape.mp4" else return "qrc:/Images/Tablet_Portrait.mp4" } } autoPlay: true loops: MediaPlayer.Infinite muted: true fillMode: VideoOutput.PreserveAspectCrop } -
Hi,
I'm running a Video component as a view's background. I have 4 different video files for 4 different device types/screen aspect ratios. Tablet_Landscape, Tablet_Portrait, Phone_Landscape and Phone_Portrait.
I'm creating a binding on the orientation to switch between the Landscape and Portrait videos for the source but I noticed that when changing the orientation the video just disappears. I do get an onSourceChanged event but the new video is not actually loaded. I've looked through the documentation and there's nothing about this. Is there something I should call to load the new source onSourceChanged and start playback or is that simply a limitation of the Video component? There's a workaround with Loaders or possibly Playlists, but I'd rather just use a Source binding as it's just more elegant.
My code:
Video { id: requirementsScreenId anchors.fill: root source: { if (isPhone()) { if (orientation === "landscape") return "qrc:/Images/Phone_Landscape.mp4" else return "qrc:/Images/Phone_Portrait.mp4" } else { if (orientation === "landscape") return "qrc:/Images/Tablet_Landscape.mp4" else return "qrc:/Images/Tablet_Portrait.mp4" } } autoPlay: true loops: MediaPlayer.Infinite muted: true fillMode: VideoOutput.PreserveAspectCrop }@Nihilish check the status of the Video Item:
https://doc.qt.io/qt-5/qml-qtmultimedia-video.html#status-propI think your paths are wrong. We only ever quality our paths with qrc in our C++ code. Not in our qml code. So you most likely have an error.
Edit: I did my grep wrong. We are qualifying some paths in QML with qrc. Now I am confused why we have a mix.
-
@Nihilish check the status of the Video Item:
https://doc.qt.io/qt-5/qml-qtmultimedia-video.html#status-propI think your paths are wrong. We only ever quality our paths with qrc in our C++ code. Not in our qml code. So you most likely have an error.
Edit: I did my grep wrong. We are qualifying some paths in QML with qrc. Now I am confused why we have a mix.