Use createObjectURL instead of readAsDataURL for videos

This commit is contained in:
Will Hunt 2018-09-26 02:04:55 +01:00 committed by GitHub
parent 60e55594dd
commit ceaa3aaca4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -148,29 +148,21 @@ function infoForImageFile(matrixClient, roomId, imageFile) {
* @return {Promise} A promise that resolves with the video image element. * @return {Promise} A promise that resolves with the video image element.
*/ */
function loadVideoElement(videoFile) { function loadVideoElement(videoFile) {
const deferred = Promise.defer();
// Load the file into an html element // Load the file into an html element
const video = document.createElement("video"); const video = document.createElement("video");
const reader = new FileReader(); // Once ready, returns its size
reader.onload = function(e) { // Wait until we have enough data to thumbnail the first frame.
video.src = e.target.result; video.onloadeddata = function() {
URL.revokeObjectURL(video.src);
// Once ready, returns its size deferred.resolve(video);
// Wait until we have enough data to thumbnail the first frame.
video.onloadeddata = function() {
deferred.resolve(video);
};
video.onerror = function(e) {
deferred.reject(e);
};
}; };
reader.onerror = function(e) { video.onerror = function(e) {
deferred.reject(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; return deferred.promise;
} }