Add unload funcs to audio and video previews.

This commit is contained in:
Lars Jung 2016-08-01 14:34:52 +02:00
parent e5966bc610
commit b7f25c45f2
3 changed files with 25 additions and 6 deletions

View file

@ -22,16 +22,23 @@ const updateGui = () => {
]); ]);
}; };
const addUnloadFn = el => {
el.unload = () => {
el.src = '';
el.load();
};
};
const load = item => { const load = item => {
return new Promise(resolve => { return new Promise(resolve => {
const $el = dom(tpl) const $el = dom(tpl)
.on('loadedmetadata', () => resolve($el)) .on('loadedmetadata', () => resolve($el))
.attr('controls', 'controls') .attr('controls', 'controls');
.attr('src', item.absHref);
if (settings.autoplay) { if (settings.autoplay) {
$el.attr('autoplay', 'autoplay'); $el.attr('autoplay', 'autoplay');
} }
addUnloadFn($el[0]);
$el.attr('src', item.absHref);
}); });
}; };

View file

@ -26,16 +26,23 @@ const updateGui = () => {
]); ]);
}; };
const addUnloadFn = el => {
el.unload = () => {
el.src = '';
el.load();
};
};
const load = item => { const load = item => {
return new Promise(resolve => { return new Promise(resolve => {
const $el = dom(tpl) const $el = dom(tpl)
.on('loadedmetadata', () => resolve($el)) .on('loadedmetadata', () => resolve($el))
.attr('controls', 'controls') .attr('controls', 'controls');
.attr('src', item.absHref);
if (settings.autoplay) { if (settings.autoplay) {
$el.attr('autoplay', 'autoplay'); $el.attr('autoplay', 'autoplay');
} }
addUnloadFn($el[0]);
$el.attr('src', item.absHref);
}); });
}; };

View file

@ -207,6 +207,11 @@ Session.prototype = {
const item = this.item; const item = this.item;
Promise.resolve() Promise.resolve()
.then(() => { .then(() => {
each(dom('#pv-container *'), el => {
if (typeof el.unload === 'function') {
el.unload();
}
});
dom('#pv-container').hide().clr(); dom('#pv-container').hide().clr();
showSpinner(true, item.thumbSquare || item.icon, 200); showSpinner(true, item.thumbSquare || item.icon, 200);
}) })