summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorJoseph Donofry <joedonofry@gmail.com>2021-11-03 23:06:32 -0400
committerJoseph Donofry <joedonofry@gmail.com>2021-11-03 23:06:32 -0400
commit8e433a7ed2f06a4ad30a6f74323ad373e8eb9cd7 (patch)
tree3d2feaf348c66b37b7bc750c57c2378606b57cb1 /src
parentUpdate video_player_enhancements with changes from master (diff)
downloadnheko-8e433a7ed2f06a4ad30a6f74323ad373e8eb9cd7.tar.xz
PlayableMediaMessage fixes on macOS
Diffstat (limited to 'src')
-rw-r--r--src/ui/MxcMediaProxy.cpp33
1 files changed, 31 insertions, 2 deletions
diff --git a/src/ui/MxcMediaProxy.cpp b/src/ui/MxcMediaProxy.cpp
index db8c0f1f..2015b420 100644
--- a/src/ui/MxcMediaProxy.cpp
+++ b/src/ui/MxcMediaProxy.cpp
@@ -13,6 +13,11 @@
 #include <QStandardPaths>
 #include <QUrl>
 
+#if defined(Q_OS_MACOS)
+// TODO (red_sky): Remove for Qt6.  See other ifdef below
+#include <QTemporaryFile>
+#endif
+
 #include "EventAccessors.h"
 #include "Logging.h"
 #include "MatrixClient.h"
@@ -75,7 +80,7 @@ MxcMediaProxy::startDownload()
 
     QPointer<MxcMediaProxy> self = this;
 
-    auto processBuffer = [this, encryptionInfo, filename, self](QIODevice &device) {
+    auto processBuffer = [this, encryptionInfo, filename, self, suffix](QIODevice &device) {
         if (!self)
             return;
 
@@ -90,10 +95,34 @@ MxcMediaProxy::startDownload()
         buffer.open(QIODevice::ReadOnly);
         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(
               "Playing buffer with size: {}, {}", buffer.bytesAvailable(), buffer.isOpen());
             this->setMedia(QMediaContent(filename.fileName()), &buffer);
+#endif
             emit loadedChanged();
         });
     };