From 49e4fd1b00b2315eb41b7dfdd493a83651d5fb95 Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Tue, 20 May 2025 18:08:23 -0400 Subject: [PATCH] Overhaul video player --- src/timeline/VideoComponent.qml | 102 ++++++++++++-------- src/timeline/models/messagecontentmodel.cpp | 10 ++ src/timeline/models/messagecontentmodel.h | 7 ++ 3 files changed, 78 insertions(+), 41 deletions(-) diff --git a/src/timeline/VideoComponent.qml b/src/timeline/VideoComponent.qml index 2cdaf2e03..0ac2b7d86 100644 --- a/src/timeline/VideoComponent.qml +++ b/src/timeline/VideoComponent.qml @@ -48,24 +48,32 @@ Video { */ required property var fileTransferInfo + /** + * @brief Whether the video should be played when downloaded. + */ + required property bool playOnFinished + /** * @brief Whether the media has been downloaded. */ readonly property bool downloaded: root.fileTransferInfo && root.fileTransferInfo.completed onDownloadedChanged: { if (downloaded) { + root.autoPlay = root.playOnFinished; root.source = root.fileTransferInfo.localPath; - } - if (downloaded && playOnFinished) { - playSavedFile(); - playOnFinished = false; + + console.info("hasAudio:" + root.hasAudio + " hasVideo:" + root.hasVideo); + + if (playOnFinished) { + //playSavedFile(); + root.Message.contentModel.setPlayOnFinished(false); + } } } - /** - * @brief Whether the video should be played when downloaded. - */ - property bool playOnFinished: false + onPaused: console.info("PAUSED") + onPlaying: console.info("PLAYING") + onStopped: console.info("STOPPED") Layout.preferredWidth: mediaSizeHelper.currentSize.width Layout.preferredHeight: mediaSizeHelper.currentSize.height @@ -87,9 +95,13 @@ Video { target: videoLabel visible: true } - PropertyChanges { + /*PropertyChanges { target: mediaThumbnail visible: true + }*/ + PropertyChanges { + target: infoBackground + visible: true } }, State { @@ -99,6 +111,14 @@ Video { target: downloadBar visible: true } + /*PropertyChanges { + target: mediaThumbnail + visible: true + }*/ + PropertyChanges { + target: infoBackground + visible: true + } }, State { name: "paused" @@ -136,10 +156,10 @@ Video { target: videoControls stateVisible: true } - PropertyChanges { + /*PropertyChanges { target: mediaThumbnail visible: true - } + }*/ PropertyChanges { target: videoLabel visible: true @@ -188,41 +208,37 @@ Video { fillMode: Image.PreserveAspectFit } - QQC2.Label { - id: videoLabel - anchors.centerIn: parent + Rectangle { + id: infoBackground + anchors.fill: parent + + color: "black" + opacity: 0.5 visible: false - color: "white" - text: i18n("Video") - font.pixelSize: 16 - - padding: 8 - - background: Rectangle { - radius: Kirigami.Units.smallSpacing - color: "black" - opacity: 0.3 - } } - Rectangle { - id: downloadBar - anchors.fill: parent + Kirigami.Icon { + id: videoLabel + + anchors.centerIn: parent visible: false + source: "media-playback-start-symbolic" + width: Kirigami.Units.iconSizes.huge + height: Kirigami.Units.iconSizes.huge + } - color: Kirigami.Theme.backgroundColor - radius: Kirigami.Units.cornerRadius + Kirigami.LoadingPlaceholder { + id: downloadBar - QQC2.ProgressBar { - anchors.centerIn: parent + anchors.centerIn: parent - width: parent.width * 0.8 - - from: 0 - to: root.fileTransferInfo.total - value: root.fileTransferInfo.progress - } + text: i18nc("@info:placeholder", "Downloading…") + visible: false + determinate: root.fileTransferInfo.progress > 0 + progressBar.from: 0 + progressBar.to: root.fileTransferInfo.total + progressBar.value: root.fileTransferInfo.progress } Rectangle { @@ -407,7 +423,7 @@ Video { acceptedButtons: Qt.LeftButton gesturePolicy: TapHandler.ReleaseWithinBounds | TapHandler.WithinBounds onTapped: if (root.fileTransferInfo.completed) { - if (root.playbackState == MediaPlayer.PlayingState) { + if (root.playbackState === MediaPlayer.PlayingState) { root.pause(); } else { MediaManager.startPlayback(); @@ -429,14 +445,18 @@ Video { if (root.downloaded) { playSavedFile(); } else { - playOnFinished = true; + //root.Message.contentModel.setPlayOnFinished(true); Message.room.downloadFile(root.eventId, Core.StandardPaths.writableLocation(Core.StandardPaths.CacheLocation) + "/" + root.eventId.replace(":", "_").replace("/", "_").replace("+", "_") + Message.room.fileNameToDownload(root.eventId)); } } function playSavedFile() { - root.stop(); MediaManager.startPlayback(); root.play(); + root.state = "playing"; + console.info("current state:" + root.state); } + + onStateChanged: console.info("state changed to " + root.state) + onErrorOccurred: (error, errorString) => console.info("ERR: " + errorString) } diff --git a/src/timeline/models/messagecontentmodel.cpp b/src/timeline/models/messagecontentmodel.cpp index 11281b178..d0ffaad8e 100644 --- a/src/timeline/models/messagecontentmodel.cpp +++ b/src/timeline/models/messagecontentmodel.cpp @@ -107,6 +107,7 @@ void MessageContentModel::initializeModel() }); connect(m_room, &NeoChatRoom::fileTransferCompleted, this, [this](const QString &eventId) { if (m_room != nullptr && eventId == m_eventId) { + setPlayOnFinished(true); resetContent(); Q_EMIT dataChanged(index(0), index(rowCount() - 1), {FileTransferInfoRole}); } @@ -377,6 +378,9 @@ QVariant MessageContentModel::data(const QModelIndex &index, int role) const } return QVariant::fromValue(m_room->editCache()); } + if (role == PlayOnFinishedrole) { + return m_playOnFinished; + } return {}; } @@ -416,6 +420,7 @@ QHash MessageContentModel::roleNamesStatic() roles[MessageContentModel::ThreadRootRole] = "threadRoot"; roles[MessageContentModel::LinkPreviewerRole] = "linkPreviewer"; roles[MessageContentModel::ChatBarCacheRole] = "chatBarCache"; + roles[MessageContentModel::PlayOnFinishedrole] = "playOnFinished"; return roles; } @@ -787,4 +792,9 @@ void MessageContentModel::setThreadsEnabled(bool enableThreads) m_threadsEnabled = enableThreads; } +void MessageContentModel::setPlayOnFinished(bool value) +{ + m_playOnFinished = value; +} + #include "moc_messagecontentmodel.cpp" diff --git a/src/timeline/models/messagecontentmodel.h b/src/timeline/models/messagecontentmodel.h index 78b6d02fb..408c07e53 100644 --- a/src/timeline/models/messagecontentmodel.h +++ b/src/timeline/models/messagecontentmodel.h @@ -65,6 +65,7 @@ public: LinkPreviewerRole, /**< The link preview details. */ ChatBarCacheRole, /**< The ChatBarCache to use. */ + PlayOnFinishedrole, /**< Whether the video should be played when downloaded. */ }; Q_ENUM(Roles) @@ -112,6 +113,11 @@ public: */ Q_INVOKABLE ThreadModel *modelForThread(const QString &threadRootId); + /** + * @brief Set whether the video should be played when downloaded. + */ + Q_INVOKABLE void setPlayOnFinished(bool value); + static void setThreadsEnabled(bool enableThreads); Q_SIGNALS: @@ -149,6 +155,7 @@ private: QList addLinkPreviews(QList inputComponents); QList m_removedLinkPreviews; + bool m_playOnFinished = false; void updateItineraryModel(); bool m_emptyItinerary = false;