getFileInfo should only fire once

This commit is contained in:
j 2016-09-19 23:12:37 +02:00
parent 0d61dcd4e0
commit 3ce0fbfb81

View file

@ -115,6 +115,7 @@ pandora.ui.addItemDialog = function(options) {
} }
function getFileInfo(file, callback) { function getFileInfo(file, callback) {
var done = false;
Ox.oshash(file, function(oshash) { Ox.oshash(file, function(oshash) {
var $video = $('<video>'), var $video = $('<video>'),
url = URL.createObjectURL(file), url = URL.createObjectURL(file),
@ -128,9 +129,15 @@ pandora.ui.addItemDialog = function(options) {
video: [] video: []
}; };
$video.one('error', function(event) { $video.one('error', function(event) {
if (!done) {
done = true;
URL.revokeObjectURL(url);
callback(info); callback(info);
}
}); });
$video.one('loadedmetadata', function(event) { $video.one('loadedmetadata', function(event) {
if (!done) {
done = true;
info.duration = $video[0].duration; info.duration = $video[0].duration;
if ($video[0].videoHeight > 0) { if ($video[0].videoHeight > 0) {
info.width = $video[0].videoWidth; info.width = $video[0].videoWidth;
@ -139,7 +146,9 @@ pandora.ui.addItemDialog = function(options) {
if (info.duration) { if (info.duration) {
info.bitrate = info.size * 8 / info.duration / 1000; info.bitrate = info.size * 8 / info.duration / 1000;
} }
URL.revokeObjectURL(url);
callback(info); callback(info);
}
}); });
$video[0].src = url; $video[0].src = url;
}); });