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 required property var fileTransferInfo
/**
* @brief Whether the video should be played when downloaded.
*/
required property bool playOnFinished
/** /**
* @brief Whether the media has been downloaded. * @brief Whether the media has been downloaded.
*/ */
readonly property bool downloaded: root.fileTransferInfo && root.fileTransferInfo.completed readonly property bool downloaded: root.fileTransferInfo && root.fileTransferInfo.completed
onDownloadedChanged: { onDownloadedChanged: {
if (downloaded) { if (downloaded) {
root.autoPlay = root.playOnFinished;
root.source = root.fileTransferInfo.localPath; root.source = root.fileTransferInfo.localPath;
}
if (downloaded && playOnFinished) { console.info("hasAudio:" + root.hasAudio + " hasVideo:" + root.hasVideo);
playSavedFile();
playOnFinished = false; if (playOnFinished) {
//playSavedFile();
root.Message.contentModel.setPlayOnFinished(false);
}
} }
} }
/** onPaused: console.info("PAUSED")
* @brief Whether the video should be played when downloaded. onPlaying: console.info("PLAYING")
*/ onStopped: console.info("STOPPED")
property bool playOnFinished: false
Layout.preferredWidth: mediaSizeHelper.currentSize.width Layout.preferredWidth: mediaSizeHelper.currentSize.width
Layout.preferredHeight: mediaSizeHelper.currentSize.height Layout.preferredHeight: mediaSizeHelper.currentSize.height
@@ -87,9 +95,13 @@ Video {
target: videoLabel target: videoLabel
visible: true visible: true
} }
PropertyChanges { /*PropertyChanges {
target: mediaThumbnail target: mediaThumbnail
visible: true visible: true
}*/
PropertyChanges {
target: infoBackground
visible: true
} }
}, },
State { State {
@@ -99,6 +111,14 @@ Video {
target: downloadBar target: downloadBar
visible: true visible: true
} }
/*PropertyChanges {
target: mediaThumbnail
visible: true
}*/
PropertyChanges {
target: infoBackground
visible: true
}
}, },
State { State {
name: "paused" name: "paused"
@@ -136,10 +156,10 @@ Video {
target: videoControls target: videoControls
stateVisible: true stateVisible: true
} }
PropertyChanges { /*PropertyChanges {
target: mediaThumbnail target: mediaThumbnail
visible: true visible: true
} }*/
PropertyChanges { PropertyChanges {
target: videoLabel target: videoLabel
visible: true visible: true
@@ -188,41 +208,37 @@ Video {
fillMode: Image.PreserveAspectFit fillMode: Image.PreserveAspectFit
} }
QQC2.Label { Rectangle {
id: videoLabel id: infoBackground
anchors.centerIn: parent
anchors.fill: parent
color: "black"
opacity: 0.5
visible: false visible: false
color: "white"
text: i18n("Video")
font.pixelSize: 16
padding: 8
background: Rectangle {
radius: Kirigami.Units.smallSpacing
color: "black"
opacity: 0.3
}
} }
Rectangle { Kirigami.Icon {
id: downloadBar id: videoLabel
anchors.fill: parent
anchors.centerIn: parent
visible: false visible: false
source: "media-playback-start-symbolic"
width: Kirigami.Units.iconSizes.huge
height: Kirigami.Units.iconSizes.huge
}
color: Kirigami.Theme.backgroundColor Kirigami.LoadingPlaceholder {
radius: Kirigami.Units.cornerRadius id: downloadBar
QQC2.ProgressBar { anchors.centerIn: parent
anchors.centerIn: parent
width: parent.width * 0.8 text: i18nc("@info:placeholder", "Downloading…")
visible: false
from: 0 determinate: root.fileTransferInfo.progress > 0
to: root.fileTransferInfo.total progressBar.from: 0
value: root.fileTransferInfo.progress progressBar.to: root.fileTransferInfo.total
} progressBar.value: root.fileTransferInfo.progress
} }
Rectangle { Rectangle {
@@ -407,7 +423,7 @@ Video {
acceptedButtons: Qt.LeftButton acceptedButtons: Qt.LeftButton
gesturePolicy: TapHandler.ReleaseWithinBounds | TapHandler.WithinBounds gesturePolicy: TapHandler.ReleaseWithinBounds | TapHandler.WithinBounds
onTapped: if (root.fileTransferInfo.completed) { onTapped: if (root.fileTransferInfo.completed) {
if (root.playbackState == MediaPlayer.PlayingState) { if (root.playbackState === MediaPlayer.PlayingState) {
root.pause(); root.pause();
} else { } else {
MediaManager.startPlayback(); MediaManager.startPlayback();
@@ -429,14 +445,18 @@ Video {
if (root.downloaded) { if (root.downloaded) {
playSavedFile(); playSavedFile();
} else { } 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)); Message.room.downloadFile(root.eventId, Core.StandardPaths.writableLocation(Core.StandardPaths.CacheLocation) + "/" + root.eventId.replace(":", "_").replace("/", "_").replace("+", "_") + Message.room.fileNameToDownload(root.eventId));
} }
} }
function playSavedFile() { function playSavedFile() {
root.stop();
MediaManager.startPlayback(); MediaManager.startPlayback();
root.play(); 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) { connect(m_room, &NeoChatRoom::fileTransferCompleted, this, [this](const QString &eventId) {
if (m_room != nullptr && eventId == m_eventId) { if (m_room != nullptr && eventId == m_eventId) {
setPlayOnFinished(true);
resetContent(); resetContent();
Q_EMIT dataChanged(index(0), index(rowCount() - 1), {FileTransferInfoRole}); 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()); return QVariant::fromValue<ChatBarCache *>(m_room->editCache());
} }
if (role == PlayOnFinishedrole) {
return m_playOnFinished;
}
return {}; return {};
} }
@@ -416,6 +420,7 @@ QHash<int, QByteArray> MessageContentModel::roleNamesStatic()
roles[MessageContentModel::ThreadRootRole] = "threadRoot"; roles[MessageContentModel::ThreadRootRole] = "threadRoot";
roles[MessageContentModel::LinkPreviewerRole] = "linkPreviewer"; roles[MessageContentModel::LinkPreviewerRole] = "linkPreviewer";
roles[MessageContentModel::ChatBarCacheRole] = "chatBarCache"; roles[MessageContentModel::ChatBarCacheRole] = "chatBarCache";
roles[MessageContentModel::PlayOnFinishedrole] = "playOnFinished";
return roles; return roles;
} }
@@ -787,4 +792,9 @@ void MessageContentModel::setThreadsEnabled(bool enableThreads)
m_threadsEnabled = enableThreads; m_threadsEnabled = enableThreads;
} }
void MessageContentModel::setPlayOnFinished(bool value)
{
m_playOnFinished = value;
}
#include "moc_messagecontentmodel.cpp" #include "moc_messagecontentmodel.cpp"

View File

@@ -65,6 +65,7 @@ public:
LinkPreviewerRole, /**< The link preview details. */ LinkPreviewerRole, /**< The link preview details. */
ChatBarCacheRole, /**< The ChatBarCache to use. */ ChatBarCacheRole, /**< The ChatBarCache to use. */
PlayOnFinishedrole, /**< Whether the video should be played when downloaded. */
}; };
Q_ENUM(Roles) Q_ENUM(Roles)
@@ -112,6 +113,11 @@ public:
*/ */
Q_INVOKABLE ThreadModel *modelForThread(const QString &threadRootId); 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); static void setThreadsEnabled(bool enableThreads);
Q_SIGNALS: Q_SIGNALS:
@@ -149,6 +155,7 @@ private:
QList<MessageComponent> addLinkPreviews(QList<MessageComponent> inputComponents); QList<MessageComponent> addLinkPreviews(QList<MessageComponent> inputComponents);
QList<QUrl> m_removedLinkPreviews; QList<QUrl> m_removedLinkPreviews;
bool m_playOnFinished = false;
void updateItineraryModel(); void updateItineraryModel();
bool m_emptyItinerary = false; bool m_emptyItinerary = false;