matrixion/resources/qml/delegates/PlayableMediaMessage.qml

108 lines
3.4 KiB
QML
Raw Permalink Normal View History

// SPDX-FileCopyrightText: Nheko Contributors
//
2021-03-05 02:35:15 +03:00
// SPDX-License-Identifier: GPL-3.0-or-later
import "../ui/media"
2023-06-02 01:43:38 +03:00
import QtMultimedia
import QtQuick
import QtQuick.Controls
import im.nheko
2021-11-11 21:18:45 +03:00
Item {
2021-11-10 06:17:00 +03:00
id: content
required property double proportionalHeight
required property int type
required property int originalWidth
2022-03-21 02:48:27 +03:00
required property int duration
required property string thumbnailUrl
required property string eventId
required property string url
required property string body
required property string filesize
2023-10-09 22:41:00 +03:00
property double divisor: EventDelegateChooser.isReply ? 10 : 4
2022-02-14 16:03:17 +03:00
property int tempWidth: originalWidth < 1? 400: originalWidth
implicitWidth: type == MtxEvent.VideoMessage ? Math.round(tempWidth*Math.min((timelineView.height/divisor)/(tempWidth*proportionalHeight), 1)) : 500
2023-06-04 04:22:57 +03:00
width: Math.min(parent?.width ?? implicitWidth, implicitWidth)
height: (type == MtxEvent.VideoMessage ? width*proportionalHeight : 80) + fileInfoLabel.height
2023-06-04 04:22:57 +03:00
//implicitHeight: height
2021-11-10 06:17:00 +03:00
2022-02-14 23:07:03 +03:00
property int metadataWidth
property bool fitsMetadata: (parent.width - fileInfoLabel.width) > metadataWidth+4
MxcMedia {
id: mxcmedia
2021-11-10 06:17:00 +03:00
2021-07-19 21:11:03 +03:00
// TODO: Show error in overlay or so?
roomm: room
2023-06-02 01:43:38 +03:00
audioOutput: AudioOutput {
muted: mediaControls.muted
volume: mediaControls.desiredVolume
}
videoOutput: videoOutput
2021-07-19 21:11:03 +03:00
}
2021-07-19 21:11:03 +03:00
Rectangle {
id: videoContainer
2021-11-11 23:32:38 +03:00
color: content.type == MtxEvent.VideoMessage ? palette.window : "transparent"
2021-11-11 21:18:45 +03:00
width: parent.width
height: parent.height - fileInfoLabel.height
2021-11-11 23:32:38 +03:00
TapHandler {
onTapped: Settings.openVideoExternal ? room.openMedia(eventId) : mediaControls.showControls()
2021-11-11 23:32:38 +03:00
}
2021-11-09 03:18:11 +03:00
2021-07-19 21:11:03 +03:00
Image {
anchors.fill: parent
source: content.thumbnailUrl ? thumbnailUrl.replace("mxc://", "image://MxcImage/") + "?scale" : "image://colorimage/:/icons/icons/ui/video-file.svg?" + palette.windowText
2021-07-19 21:11:03 +03:00
asynchronous: true
fillMode: Image.PreserveAspectFit
2021-11-10 06:17:00 +03:00
2021-07-19 21:11:03 +03:00
VideoOutput {
id: videoOutput
2021-11-10 07:52:59 +03:00
visible: content.type == MtxEvent.VideoMessage
2021-07-19 21:11:03 +03:00
clip: true
anchors.fill: parent
fillMode: VideoOutput.PreserveAspectFit
orientation: mxcmedia.orientation
}
2021-11-11 21:18:45 +03:00
}
2023-06-04 04:22:57 +03:00
MediaControls {
id: mediaControls
anchors.left: videoContainer.left
anchors.right: videoContainer.right
anchors.bottom: videoContainer.bottom
playingVideo: content.type == MtxEvent.VideoMessage
2023-06-04 04:22:57 +03:00
positionValue: mxcmedia.position
duration: mediaLoaded ? mxcmedia.duration : content.duration
mediaLoaded: mxcmedia.loaded
mediaState: mxcmedia.playbackState
onPositionChanged: mxcmedia.position = position
onPlayPauseActivated: mxcmedia.playbackState == MediaPlayer.PlayingState ? mxcmedia.pause() : mxcmedia.play()
onLoadActivated: mxcmedia.eventId = eventId
}
2021-11-11 23:32:38 +03:00
}
2021-11-10 06:17:00 +03:00
2021-11-10 07:52:59 +03:00
// information about file name and file size
2021-11-10 06:17:00 +03:00
Label {
id: fileInfoLabel
2023-06-04 04:22:57 +03:00
anchors.top: videoContainer.bottom
text: content.body + " [" + filesize + "]"
textFormat: Text.RichText
2021-11-10 06:17:00 +03:00
elide: Text.ElideRight
color: palette.text
2021-11-10 06:17:00 +03:00
background: Rectangle {
color: palette.base
2021-11-10 06:17:00 +03:00
}
}
2021-07-19 21:11:03 +03:00
2021-11-10 06:17:00 +03:00
}