nheko/resources/qml/delegates/PlayableMediaMessage.qml

215 lines
6.1 KiB
QML
Raw Normal View History

2021-03-05 00:35:15 +01:00
// SPDX-FileCopyrightText: 2021 Nheko Contributors
//
2021-03-05 00:35:15 +01:00
// SPDX-License-Identifier: GPL-3.0-or-later
2021-03-27 01:17:58 +01:00
import "../"
import QtMultimedia 5.6
2021-02-14 01:28:28 +01:00
import QtQuick 2.12
import QtQuick.Controls 2.1
import QtQuick.Layouts 1.2
import im.nheko 1.0
2019-10-05 23:11:20 +02:00
Rectangle {
2020-10-08 21:11:21 +02:00
id: bg
2019-10-05 23:11:20 +02:00
2020-10-08 21:11:21 +02:00
radius: 10
2021-05-13 08:23:56 +02:00
color: Nheko.colors.alternateBase
2020-10-08 21:11:21 +02:00
height: Math.round(content.height + 24)
width: parent ? parent.width : undefined
Column {
id: content
width: parent.width - 24
anchors.centerIn: parent
Rectangle {
id: videoContainer
property double tempWidth: Math.min(parent ? parent.width : undefined, model.data.width < 1 ? 400 : model.data.width)
property double tempHeight: tempWidth * model.data.proportionalHeight
property double divisor: model.isReply ? 4 : 2
property bool tooHigh: tempHeight > timelineView.height / divisor
2020-10-08 21:11:21 +02:00
visible: model.data.type == MtxEvent.VideoMessage
height: tooHigh ? timelineView.height / divisor : tempHeight
width: tooHigh ? (timelineView.height / divisor) / model.data.proportionalHeight : tempWidth
2020-10-08 21:11:21 +02:00
Image {
anchors.fill: parent
source: model.data.thumbnailUrl.replace("mxc://", "image://MxcImage/")
asynchronous: true
fillMode: Image.PreserveAspectFit
VideoOutput {
anchors.fill: parent
fillMode: VideoOutput.PreserveAspectFit
source: media
}
}
}
RowLayout {
width: parent.width
Text {
id: positionText
text: "--:--:--"
2021-05-13 08:23:56 +02:00
color: Nheko.colors.text
2020-10-08 21:11:21 +02:00
}
Slider {
id: progress
//indeterminate: true
function updatePositionTexts() {
function formatTime(date) {
var hh = date.getUTCHours();
var mm = date.getUTCMinutes();
var ss = date.getSeconds();
if (hh < 10)
hh = "0" + hh;
if (mm < 10)
mm = "0" + mm;
if (ss < 10)
ss = "0" + ss;
return hh + ":" + mm + ":" + ss;
}
positionText.text = formatTime(new Date(media.position));
durationText.text = formatTime(new Date(media.duration));
}
Layout.fillWidth: true
value: media.position
from: 0
to: media.duration
onMoved: media.seek(value)
onValueChanged: updatePositionTexts()
2021-05-13 08:23:56 +02:00
palette: Nheko.colors
2020-10-08 21:11:21 +02:00
}
Text {
id: durationText
text: "--:--:--"
2021-05-13 08:23:56 +02:00
color: Nheko.colors.text
2020-10-08 21:11:21 +02:00
}
}
RowLayout {
width: parent.width
spacing: 15
2021-03-27 01:17:58 +01:00
ImageButton {
2020-10-08 21:11:21 +02:00
id: button
2021-04-09 14:12:37 +02:00
Layout.alignment: Qt.AlignVCenter
2021-05-13 08:23:56 +02:00
//color: Nheko.colors.window
2021-03-27 01:17:58 +01:00
//radius: 22
height: 32
width: 32
z: 3
image: ":/icons/icons/ui/arrow-pointing-down.png"
onClicked: {
switch (button.state) {
case "":
room.cacheMedia(model.data.id);
2021-03-27 01:17:58 +01:00
break;
case "stopped":
media.play();
console.log("play");
button.state = "playing";
break;
case "playing":
media.pause();
console.log("pause");
button.state = "stopped";
break;
}
}
2020-10-08 21:11:21 +02:00
states: [
State {
name: "stopped"
PropertyChanges {
2021-03-27 01:17:58 +01:00
target: button
image: ":/icons/icons/ui/play-sign.png"
2020-10-08 21:11:21 +02:00
}
},
State {
name: "playing"
PropertyChanges {
2021-03-27 01:17:58 +01:00
target: button
image: ":/icons/icons/ui/pause-symbol.png"
2020-10-08 21:11:21 +02:00
}
}
]
2021-02-14 01:28:28 +01:00
CursorShape {
anchors.fill: parent
2020-10-08 21:11:21 +02:00
cursorShape: Qt.PointingHandCursor
}
MediaPlayer {
id: media
onError: console.log(errorString)
onStatusChanged: {
if (status == MediaPlayer.Loaded)
progress.updatePositionTexts();
}
onStopped: button.state = "stopped"
}
Connections {
target: room
2020-10-08 21:11:21 +02:00
onMediaCached: {
if (mxcUrl == model.data.url) {
2021-03-14 18:46:41 +01:00
media.source = cacheUrl;
2020-10-08 21:11:21 +02:00
button.state = "stopped";
console.log("media loaded: " + mxcUrl + " at " + cacheUrl);
}
console.log("media cached: " + mxcUrl + " at " + cacheUrl);
}
}
}
ColumnLayout {
id: col
Text {
Layout.fillWidth: true
text: model.data.body
elide: Text.ElideRight
2021-05-13 08:23:56 +02:00
color: Nheko.colors.text
2020-10-08 21:11:21 +02:00
}
Text {
Layout.fillWidth: true
text: model.data.filesize
textFormat: Text.PlainText
elide: Text.ElideRight
2021-05-13 08:23:56 +02:00
color: Nheko.colors.text
2020-10-08 21:11:21 +02:00
}
}
}
}
}