From ceaa3aaca4a61046ac03f7dbb23d670b57c49d16 Mon Sep 17 00:00:00 2001 From: Will Hunt Date: Wed, 26 Sep 2018 02:04:55 +0100 Subject: [PATCH] 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; }