mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-12-01 14:58:47 +03:00
PlayableMediaMessage fixes on macOS
This commit is contained in:
parent
743a83c8e6
commit
8e433a7ed2
1 changed files with 31 additions and 2 deletions
|
@ -13,6 +13,11 @@
|
||||||
#include <QStandardPaths>
|
#include <QStandardPaths>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
|
|
||||||
|
#if defined(Q_OS_MACOS)
|
||||||
|
// TODO (red_sky): Remove for Qt6. See other ifdef below
|
||||||
|
#include <QTemporaryFile>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "EventAccessors.h"
|
#include "EventAccessors.h"
|
||||||
#include "Logging.h"
|
#include "Logging.h"
|
||||||
#include "MatrixClient.h"
|
#include "MatrixClient.h"
|
||||||
|
@ -75,7 +80,7 @@ MxcMediaProxy::startDownload()
|
||||||
|
|
||||||
QPointer<MxcMediaProxy> self = this;
|
QPointer<MxcMediaProxy> self = this;
|
||||||
|
|
||||||
auto processBuffer = [this, encryptionInfo, filename, self](QIODevice &device) {
|
auto processBuffer = [this, encryptionInfo, filename, self, suffix](QIODevice &device) {
|
||||||
if (!self)
|
if (!self)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -90,10 +95,34 @@ MxcMediaProxy::startDownload()
|
||||||
buffer.open(QIODevice::ReadOnly);
|
buffer.open(QIODevice::ReadOnly);
|
||||||
buffer.reset();
|
buffer.reset();
|
||||||
|
|
||||||
QTimer::singleShot(0, this, [this, filename] {
|
QTimer::singleShot(0, this, [this, filename, suffix, encryptionInfo] {
|
||||||
|
#if defined(Q_OS_MACOS)
|
||||||
|
if (encryptionInfo) {
|
||||||
|
// macOS has issues reading from a buffer in setMedia for whatever reason.
|
||||||
|
// Instead, write the buffer to a temporary file and read from that.
|
||||||
|
// This should be fixed in Qt6, so update this when we do that!
|
||||||
|
// TODO: REMOVE IN QT6
|
||||||
|
QTemporaryFile tempFile;
|
||||||
|
tempFile.setFileTemplate(tempFile.fileTemplate() + QLatin1Char('.') + suffix);
|
||||||
|
tempFile.open();
|
||||||
|
tempFile.write(buffer.data());
|
||||||
|
tempFile.close();
|
||||||
|
nhlog::ui()->debug("Playing media from temp buffer file: {}. Remove in QT6!",
|
||||||
|
filename.filePath().toStdString());
|
||||||
|
this->setMedia(QUrl::fromLocalFile(tempFile.fileName()));
|
||||||
|
} else {
|
||||||
|
nhlog::ui()->info(
|
||||||
|
"Playing buffer with size: {}, {}", buffer.bytesAvailable(), buffer.isOpen());
|
||||||
|
this->setMedia(QUrl::fromLocalFile(filename.filePath()));
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
Q_UNSUED(suffix)
|
||||||
|
Q_UNUSED(encryptionInfo)
|
||||||
|
|
||||||
nhlog::ui()->info(
|
nhlog::ui()->info(
|
||||||
"Playing buffer with size: {}, {}", buffer.bytesAvailable(), buffer.isOpen());
|
"Playing buffer with size: {}, {}", buffer.bytesAvailable(), buffer.isOpen());
|
||||||
this->setMedia(QMediaContent(filename.fileName()), &buffer);
|
this->setMedia(QMediaContent(filename.fileName()), &buffer);
|
||||||
|
#endif
|
||||||
emit loadedChanged();
|
emit loadedChanged();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue