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('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);
}

View file

@ -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 });
};