VideoDelegate: Detect if the server supports streaming videos.

This commit is contained in:
Black Hat
2019-10-06 02:44:28 -07:00
parent b8f6a1d45f
commit e79d5f47d4
2 changed files with 40 additions and 6 deletions

View File

@@ -76,7 +76,7 @@ RowLayout {
onClicked: { onClicked: {
if (audio.playbackState == Audio.PlayingState) { if (audio.playbackState == Audio.PlayingState) {
audio.stop() audio.pause()
} else { } else {
audio.play() audio.play()
} }

View File

@@ -23,6 +23,8 @@ RowLayout {
property bool playOnFinished: false property bool playOnFinished: false
readonly property bool downloaded: progressInfo && progressInfo.completed readonly property bool downloaded: progressInfo && progressInfo.completed
property bool supportStreaming: true
id: root id: root
spacing: 4 spacing: 4
@@ -30,6 +32,10 @@ RowLayout {
z: -5 z: -5
onDownloadedChanged: { onDownloadedChanged: {
if (downloaded) {
vid.source = progressInfo.localPath
}
if (downloaded && openOnFinished) { if (downloaded && openOnFinished) {
openSavedFile() openSavedFile()
openOnFinished = false openOnFinished = false
@@ -80,14 +86,32 @@ RowLayout {
id: vid id: vid
source: progressInfo.completed ? progressInfo.localPath : ""
loops: MediaPlayer.Infinite loops: MediaPlayer.Infinite
autoPlay: true autoPlay: true
fillMode: VideoOutput.PreserveAspectFit 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.enabled: true
layer.effect: OpacityMask { layer.effect: OpacityMask {
@@ -104,7 +128,7 @@ RowLayout {
anchors.fill: parent 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 : "") source: "image://mxc/" + (isThumbnail ? content.thumbnailMediaId : "")
@@ -184,7 +208,17 @@ RowLayout {
id: messageMouseArea id: messageMouseArea
onPrimaryClicked: downloadAndPlay() onPrimaryClicked: {
if (supportStreaming || progressInfo.completed) {
if (vid.playbackState == MediaPlayer.PlayingState) {
vid.pause()
} else {
vid.play()
}
} else {
downloadAndPlay()
}
}
onSecondaryClicked: { onSecondaryClicked: {
var contextMenu = imageDelegateContextMenu.createObject(ApplicationWindow.overlay) var contextMenu = imageDelegateContextMenu.createObject(ApplicationWindow.overlay)