From 573a26021b877012c576bfb2ee8b431009815858 Mon Sep 17 00:00:00 2001 From: Scott Nonnenberg Date: Sat, 21 Jul 2018 12:28:37 -0700 Subject: [PATCH] file_input_view: Use makeVideoThumbnail on attach of video --- js/modules/types/visual_attachment.js | 20 ++++++++++++++------ js/views/file_input_view.js | 7 ++++--- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/js/modules/types/visual_attachment.js b/js/modules/types/visual_attachment.js index 3246e6d5ae3b..955d1b9d60cb 100644 --- a/js/modules/types/visual_attachment.js +++ b/js/modules/types/visual_attachment.js @@ -98,33 +98,41 @@ exports.makeVideoScreenshot = ({ video.addEventListener('canplay', capture); video.addEventListener('error', error => { - logger.error('makeVideoThumbnail error', toLogFormat(error)); + logger.error('makeVideoScreenshot error', toLogFormat(error)); reject(error); }); video.src = objectUrl; }); -exports.makeVideoThumbnail = async ({ size, videoObjectUrl, logger }) => { +exports.makeVideoThumbnail = async ({ + size, + videoObjectUrl, + logger, + contentType, +}) => { let screenshotObjectUrl; try { - const type = 'image/png'; const blob = await exports.makeVideoScreenshot({ objectUrl: videoObjectUrl, - contentType: type, + contentType, logger, }); const data = await blobToArrayBuffer(blob); screenshotObjectUrl = arrayBufferToObjectURL({ data, - type, + type: contentType, }); - return exports.makeImageThumbnail({ + // We need to wait for this, otherwise the finally below will run first + const resultBlob = await exports.makeImageThumbnail({ size, objectUrl: screenshotObjectUrl, + contentType, logger, }); + + return resultBlob; } finally { exports.revokeObjectUrl(screenshotObjectUrl); } diff --git a/js/views/file_input_view.js b/js/views/file_input_view.js index 1c3873848599..76e02388104d 100644 --- a/js/views/file_input_view.js +++ b/js/views/file_input_view.js @@ -161,8 +161,9 @@ // we use the variable on this here to ensure cleanup if we're interrupted this.previewObjectUrl = URL.createObjectURL(file); const type = 'image/png'; - const thumbnail = await VisualAttachment.makeVideoScreenshot({ - objectUrl: this.previewObjectUrl, + const thumbnail = await VisualAttachment.makeVideoThumbnail({ + size: 100, + videoObjectUrl: this.previewObjectUrl, contentType: type, logger: window.log, }); @@ -171,7 +172,7 @@ const data = await VisualAttachment.blobToArrayBuffer(thumbnail); this.previewObjectUrl = Signal.Util.arrayBufferToObjectURL({ data, - type: 'image/png', + type, }); this.addThumb(this.previewObjectUrl, { addPlayIcon: true }); };