Compare commits

...

1 Commits

Author SHA1 Message Date
Joshua Goins
49e4fd1b00 Overhaul video player 2025-05-20 18:08:23 -04:00
3 changed files with 78 additions and 41 deletions

View File

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

View File

@@ -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<ChatBarCache *>(m_room->editCache());
}
if (role == PlayOnFinishedrole) {
return m_playOnFinished;
}
return {};
}
@@ -416,6 +420,7 @@ QHash<int, QByteArray> 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"

View File

@@ -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<MessageComponent> addLinkPreviews(QList<MessageComponent> inputComponents);
QList<QUrl> m_removedLinkPreviews;
bool m_playOnFinished = false;
void updateItineraryModel();
bool m_emptyItinerary = false;