forked from 0x2620/pandora
getFileInfo should only fire once
This commit is contained in:
parent
0d61dcd4e0
commit
3ce0fbfb81
1 changed files with 18 additions and 9 deletions
|
@ -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,18 +129,26 @@ pandora.ui.addItemDialog = function(options) {
|
||||||
video: []
|
video: []
|
||||||
};
|
};
|
||||||
$video.one('error', function(event) {
|
$video.one('error', function(event) {
|
||||||
callback(info);
|
if (!done) {
|
||||||
|
done = true;
|
||||||
|
URL.revokeObjectURL(url);
|
||||||
|
callback(info);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
$video.one('loadedmetadata', function(event) {
|
$video.one('loadedmetadata', function(event) {
|
||||||
info.duration = $video[0].duration;
|
if (!done) {
|
||||||
if ($video[0].videoHeight > 0) {
|
done = true;
|
||||||
info.width = $video[0].videoWidth;
|
info.duration = $video[0].duration;
|
||||||
info.height = $video[0].videoHeight;
|
if ($video[0].videoHeight > 0) {
|
||||||
|
info.width = $video[0].videoWidth;
|
||||||
|
info.height = $video[0].videoHeight;
|
||||||
|
}
|
||||||
|
if (info.duration) {
|
||||||
|
info.bitrate = info.size * 8 / info.duration / 1000;
|
||||||
|
}
|
||||||
|
URL.revokeObjectURL(url);
|
||||||
|
callback(info);
|
||||||
}
|
}
|
||||||
if (info.duration) {
|
|
||||||
info.bitrate = info.size * 8 / info.duration / 1000;
|
|
||||||
}
|
|
||||||
callback(info);
|
|
||||||
});
|
});
|
||||||
$video[0].src = url;
|
$video[0].src = url;
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue