From e79d5f47d4a45145a849e0822c63aae5a198759a Mon Sep 17 00:00:00 2001 From: Black Hat Date: Sun, 6 Oct 2019 02:44:28 -0700 Subject: [PATCH] VideoDelegate: Detect if the server supports streaming videos. --- .../Component/Timeline/AudioDelegate.qml | 2 +- .../Component/Timeline/VideoDelegate.qml | 44 ++++++++++++++++--- 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/imports/Spectral/Component/Timeline/AudioDelegate.qml b/imports/Spectral/Component/Timeline/AudioDelegate.qml index b7a5a7cbb..b5b43fc8d 100644 --- a/imports/Spectral/Component/Timeline/AudioDelegate.qml +++ b/imports/Spectral/Component/Timeline/AudioDelegate.qml @@ -76,7 +76,7 @@ RowLayout { onClicked: { if (audio.playbackState == Audio.PlayingState) { - audio.stop() + audio.pause() } else { audio.play() } diff --git a/imports/Spectral/Component/Timeline/VideoDelegate.qml b/imports/Spectral/Component/Timeline/VideoDelegate.qml index a9ed79116..626ef7795 100644 --- a/imports/Spectral/Component/Timeline/VideoDelegate.qml +++ b/imports/Spectral/Component/Timeline/VideoDelegate.qml @@ -23,6 +23,8 @@ RowLayout { property bool playOnFinished: false readonly property bool downloaded: progressInfo && progressInfo.completed + property bool supportStreaming: true + id: root spacing: 4 @@ -30,6 +32,10 @@ RowLayout { z: -5 onDownloadedChanged: { + if (downloaded) { + vid.source = progressInfo.localPath + } + if (downloaded && openOnFinished) { openSavedFile() openOnFinished = false @@ -80,14 +86,32 @@ RowLayout { id: vid - source: progressInfo.completed ? progressInfo.localPath : "" - loops: MediaPlayer.Infinite autoPlay: true fillMode: VideoOutput.PreserveAspectFit - onErrorChanged: console.log("Video playback error: " + errorString) + Component.onCompleted: { + if (downloaded) { + source = progressInfo.localPath + } else { + source = currentRoom.urlToMxcUrl(content.url) + } + } + + onDurationChanged: { + if (!duration) { + console.log("This server does not support media streaming") + supportStreaming = false; + } + } + + onErrorChanged: { + if (error != MediaPlayer.NoError) { + console.log("This server does not support media streaming") + supportStreaming = false; + } + } layer.enabled: true layer.effect: OpacityMask { @@ -104,7 +128,7 @@ RowLayout { anchors.fill: parent - visible: isThumbnail && vid.playbackState != MediaPlayer.PlayingState + visible: isThumbnail && (vid.playbackState == MediaPlayer.StoppedState || vid.error != MediaPlayer.NoError) source: "image://mxc/" + (isThumbnail ? content.thumbnailMediaId : "") @@ -184,7 +208,17 @@ RowLayout { id: messageMouseArea - onPrimaryClicked: downloadAndPlay() + onPrimaryClicked: { + if (supportStreaming || progressInfo.completed) { + if (vid.playbackState == MediaPlayer.PlayingState) { + vid.pause() + } else { + vid.play() + } + } else { + downloadAndPlay() + } + } onSecondaryClicked: { var contextMenu = imageDelegateContextMenu.createObject(ApplicationWindow.overlay)