diff --git a/js/modules/types/visual_attachment.js b/js/modules/types/visual_attachment.js index 3246e6d5a..955d1b9d6 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 1c3873848..76e023881 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 }); };