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: {
if (audio.playbackState == Audio.PlayingState) {
audio.stop()
audio.pause()
} else {
audio.play()
}

View File

@@ -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)