From ceaa3aaca4a61046ac03f7dbb23d670b57c49d16 Mon Sep 17 00:00:00 2001 From: Will Hunt Date: Wed, 26 Sep 2018 02:04:55 +0100 Subject: [PATCH 1/3] Use createObjectURL instead of readAsDataURL for videos --- src/ContentMessages.js | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/src/ContentMessages.js b/src/ContentMessages.js index fd21977108..2308954846 100644 --- a/src/ContentMessages.js +++ b/src/ContentMessages.js @@ -148,29 +148,21 @@ function infoForImageFile(matrixClient, roomId, imageFile) { * @return {Promise} A promise that resolves with the video image element. */ function loadVideoElement(videoFile) { - const deferred = Promise.defer(); - // Load the file into an html element const video = document.createElement("video"); - const reader = new FileReader(); - reader.onload = function(e) { - video.src = e.target.result; - - // Once ready, returns its size - // Wait until we have enough data to thumbnail the first frame. - video.onloadeddata = function() { - deferred.resolve(video); - }; - video.onerror = function(e) { - deferred.reject(e); - }; + // Once ready, returns its size + // Wait until we have enough data to thumbnail the first frame. + video.onloadeddata = function() { + URL.revokeObjectURL(video.src); + deferred.resolve(video); }; - reader.onerror = function(e) { + video.onerror = function(e) { deferred.reject(e); }; - reader.readAsDataURL(videoFile); - + + // We don't use readAsDataURL because massive files and b64 don't mix. + video.src = URL.createObjectURL(videoFile); return deferred.promise; } From 41336a9de69b64372eff22730c9dc9ae89f425b2 Mon Sep 17 00:00:00 2001 From: Will Hunt Date: Wed, 26 Sep 2018 02:06:02 +0100 Subject: [PATCH 2/3] Oops, missing deferred --- src/ContentMessages.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ContentMessages.js b/src/ContentMessages.js index 2308954846..0a361ae5b9 100644 --- a/src/ContentMessages.js +++ b/src/ContentMessages.js @@ -148,6 +148,8 @@ function infoForImageFile(matrixClient, roomId, imageFile) { * @return {Promise} A promise that resolves with the video image element. */ function loadVideoElement(videoFile) { + const deferred = Promise.defer(); + // Load the file into an html element const video = document.createElement("video"); From 259063eda6ef9b7651acc342a3275386b386a525 Mon Sep 17 00:00:00 2001 From: Will Hunt Date: Wed, 3 Oct 2018 10:39:09 +0100 Subject: [PATCH 3/3] Remove useless comment. --- src/ContentMessages.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/ContentMessages.js b/src/ContentMessages.js index 0a361ae5b9..a0bf75bccf 100644 --- a/src/ContentMessages.js +++ b/src/ContentMessages.js @@ -153,7 +153,6 @@ function loadVideoElement(videoFile) { // Load the file into an html element const video = document.createElement("video"); - // Once ready, returns its size // Wait until we have enough data to thumbnail the first frame. video.onloadeddata = function() { URL.revokeObjectURL(video.src);