file_input_view: Use makeVideoThumbnail on attach of video

This commit is contained in:
Scott Nonnenberg 2018-07-21 12:28:37 -07:00
parent 5933a34a18
commit 573a26021b
2 changed files with 18 additions and 9 deletions

View file

@ -98,33 +98,41 @@ exports.makeVideoScreenshot = ({
video.addEventListener('canplay', capture); video.addEventListener('canplay', capture);
video.addEventListener('error', error => { video.addEventListener('error', error => {
logger.error('makeVideoThumbnail error', toLogFormat(error)); logger.error('makeVideoScreenshot error', toLogFormat(error));
reject(error); reject(error);
}); });
video.src = objectUrl; video.src = objectUrl;
}); });
exports.makeVideoThumbnail = async ({ size, videoObjectUrl, logger }) => { exports.makeVideoThumbnail = async ({
size,
videoObjectUrl,
logger,
contentType,
}) => {
let screenshotObjectUrl; let screenshotObjectUrl;
try { try {
const type = 'image/png';
const blob = await exports.makeVideoScreenshot({ const blob = await exports.makeVideoScreenshot({
objectUrl: videoObjectUrl, objectUrl: videoObjectUrl,
contentType: type, contentType,
logger, logger,
}); });
const data = await blobToArrayBuffer(blob); const data = await blobToArrayBuffer(blob);
screenshotObjectUrl = arrayBufferToObjectURL({ screenshotObjectUrl = arrayBufferToObjectURL({
data, 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, size,
objectUrl: screenshotObjectUrl, objectUrl: screenshotObjectUrl,
contentType,
logger, logger,
}); });
return resultBlob;
} finally { } finally {
exports.revokeObjectUrl(screenshotObjectUrl); exports.revokeObjectUrl(screenshotObjectUrl);
} }

View file

@ -161,8 +161,9 @@
// we use the variable on this here to ensure cleanup if we're interrupted // we use the variable on this here to ensure cleanup if we're interrupted
this.previewObjectUrl = URL.createObjectURL(file); this.previewObjectUrl = URL.createObjectURL(file);
const type = 'image/png'; const type = 'image/png';
const thumbnail = await VisualAttachment.makeVideoScreenshot({ const thumbnail = await VisualAttachment.makeVideoThumbnail({
objectUrl: this.previewObjectUrl, size: 100,
videoObjectUrl: this.previewObjectUrl,
contentType: type, contentType: type,
logger: window.log, logger: window.log,
}); });
@ -171,7 +172,7 @@
const data = await VisualAttachment.blobToArrayBuffer(thumbnail); const data = await VisualAttachment.blobToArrayBuffer(thumbnail);
this.previewObjectUrl = Signal.Util.arrayBufferToObjectURL({ this.previewObjectUrl = Signal.Util.arrayBufferToObjectURL({
data, data,
type: 'image/png', type,
}); });
this.addThumb(this.previewObjectUrl, { addPlayIcon: true }); this.addThumb(this.previewObjectUrl, { addPlayIcon: true });
}; };