Merge pull request #2197 from matrix-org/hs/object-urls-video

Use createObjectURL instead of readAsDataURL for videos
pull/21833/head
Travis Ralston 2018-10-04 13:57:50 -06:00 committed by GitHub
commit aea9dbe1b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 15 deletions

View File

@ -153,24 +153,17 @@ function loadVideoElement(videoFile) {
// Load the file into an html element
const video = document.createElement("video");
const reader = new FileReader();
reader.onload = function(e) {
video.src = e.target.result;
// Once ready, returns its size
// Wait until we have enough data to thumbnail the first frame.
video.onloadeddata = function() {
deferred.resolve(video);
};
video.onerror = function(e) {
deferred.reject(e);
};
// Wait until we have enough data to thumbnail the first frame.
video.onloadeddata = function() {
URL.revokeObjectURL(video.src);
deferred.resolve(video);
};
reader.onerror = function(e) {
video.onerror = function(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;
}