mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-29 11:11:20 -08:00
截图工具添加销毁方法
This commit is contained in:
1 parent
a47bfb9d31
commit
99614d0717
2 files changed
+45
-21
No files matched your search
@@ -115,34 +115,30 @@
|
|||||||
|
|
||||||
var inherits = _inherits;
|
var inherits = _inherits;
|
||||||
|
|
||||||
function E () {
|
function E() {// Keep this empty so it's easier to inherit from
|
||||||
// Keep this empty so it's easier to inherit from
|
|
||||||
// (via https://github.com/lipsmack from https://github.com/scottcorgan/tiny-emitter/issues/3)
|
// (via https://github.com/lipsmack from https://github.com/scottcorgan/tiny-emitter/issues/3)
|
||||||
}
|
}
|
||||||
|
|
||||||
E.prototype = {
|
E.prototype = {
|
||||||
on: function (name, callback, ctx) {
|
on: function on(name, callback, ctx) {
|
||||||
var e = this.e || (this.e = {});
|
var e = this.e || (this.e = {});
|
||||||
|
|
||||||
(e[name] || (e[name] = [])).push({
|
(e[name] || (e[name] = [])).push({
|
||||||
fn: callback,
|
fn: callback,
|
||||||
ctx: ctx
|
ctx: ctx
|
||||||
});
|
});
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
once: function once(name, callback, ctx) {
|
||||||
once: function (name, callback, ctx) {
|
|
||||||
var self = this;
|
var self = this;
|
||||||
function listener () {
|
|
||||||
|
function listener() {
|
||||||
self.off(name, listener);
|
self.off(name, listener);
|
||||||
callback.apply(ctx, arguments);
|
callback.apply(ctx, arguments);
|
||||||
}
|
}
|
||||||
listener._ = callback;
|
listener._ = callback;
|
||||||
return this.on(name, listener, ctx);
|
return this.on(name, listener, ctx);
|
||||||
},
|
},
|
||||||
|
emit: function emit(name) {
|
||||||
emit: function (name) {
|
|
||||||
var data = [].slice.call(arguments, 1);
|
var data = [].slice.call(arguments, 1);
|
||||||
var evtArr = ((this.e || (this.e = {}))[name] || []).slice();
|
var evtArr = ((this.e || (this.e = {}))[name] || []).slice();
|
||||||
var i = 0;
|
var i = 0;
|
||||||
@@ -154,31 +150,24 @@
|
|||||||
|
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
off: function off(name, callback) {
|
||||||
off: function (name, callback) {
|
|
||||||
var e = this.e || (this.e = {});
|
var e = this.e || (this.e = {});
|
||||||
var evts = e[name];
|
var evts = e[name];
|
||||||
var liveEvents = [];
|
var liveEvents = [];
|
||||||
|
|
||||||
if (evts && callback) {
|
if (evts && callback) {
|
||||||
for (var i = 0, len = evts.length; i < len; i++) {
|
for (var i = 0, len = evts.length; i < len; i++) {
|
||||||
if (evts[i].fn !== callback && evts[i].fn._ !== callback)
|
if (evts[i].fn !== callback && evts[i].fn._ !== callback) liveEvents.push(evts[i]);
|
||||||
liveEvents.push(evts[i]);
|
|
||||||
}
|
}
|
||||||
}
|
} // Remove event from queue to prevent memory leak
|
||||||
|
|
||||||
// Remove event from queue to prevent memory leak
|
|
||||||
// Suggested by https://github.com/lazd
|
// Suggested by https://github.com/lazd
|
||||||
// Ref: https://github.com/scottcorgan/tiny-emitter/commit/c6ebfaa9bc973b33d110a84a307742b7cf94c953#commitcomment-5024910
|
// Ref: https://github.com/scottcorgan/tiny-emitter/commit/c6ebfaa9bc973b33d110a84a307742b7cf94c953#commitcomment-5024910
|
||||||
|
|
||||||
(liveEvents.length)
|
|
||||||
? e[name] = liveEvents
|
|
||||||
: delete e[name];
|
|
||||||
|
|
||||||
|
liveEvents.length ? e[name] = liveEvents : delete e[name];
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var tinyEmitter = E;
|
var tinyEmitter = E;
|
||||||
|
|
||||||
function sleep(ms) {
|
function sleep(ms) {
|
||||||
@@ -300,6 +289,10 @@
|
|||||||
return sleep(delay).then(function () {
|
return sleep(delay).then(function () {
|
||||||
context2D.drawImage(_this4.video, item.x, item.y, width, height);
|
context2D.drawImage(_this4.video, item.x, item.y, width, height);
|
||||||
canvas.toBlob(function (blob) {
|
canvas.toBlob(function (blob) {
|
||||||
|
if (_this4.thumbnailUrl) {
|
||||||
|
URL.revokeObjectURL(_this4.thumbnailUrl);
|
||||||
|
}
|
||||||
|
|
||||||
_this4.thumbnailUrl = URL.createObjectURL(blob);
|
_this4.thumbnailUrl = URL.createObjectURL(blob);
|
||||||
|
|
||||||
_this4.emit('update', _this4.thumbnailUrl, (index + 1) / number);
|
_this4.emit('update', _this4.thumbnailUrl, (index + 1) / number);
|
||||||
@@ -396,6 +389,22 @@
|
|||||||
throw new Error(msg);
|
throw new Error(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}, {
|
||||||
|
key: "destroy",
|
||||||
|
value: function destroy() {
|
||||||
|
this.option.fileInput.removeEventListener('change', this.inputChange);
|
||||||
|
document.body.removeChild(this.video);
|
||||||
|
|
||||||
|
if (this.videoUrl) {
|
||||||
|
URL.revokeObjectURL(this.videoUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.thumbnailUrl) {
|
||||||
|
URL.revokeObjectURL(this.thumbnailUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.emit('destroy');
|
||||||
|
}
|
||||||
}], [{
|
}], [{
|
||||||
key: "creatVideo",
|
key: "creatVideo",
|
||||||
value: function creatVideo() {
|
value: function creatVideo() {
|
||||||
|
|||||||
@@ -95,6 +95,9 @@ class ArtplayerToolThumbnail extends Emitter {
|
|||||||
.then(() => {
|
.then(() => {
|
||||||
context2D.drawImage(this.video, item.x, item.y, width, height);
|
context2D.drawImage(this.video, item.x, item.y, width, height);
|
||||||
canvas.toBlob(blob => {
|
canvas.toBlob(blob => {
|
||||||
|
if (this.thumbnailUrl) {
|
||||||
|
URL.revokeObjectURL(this.thumbnailUrl);
|
||||||
|
}
|
||||||
this.thumbnailUrl = URL.createObjectURL(blob);
|
this.thumbnailUrl = URL.createObjectURL(blob);
|
||||||
this.emit('update', this.thumbnailUrl, (index + 1) / number);
|
this.emit('update', this.thumbnailUrl, (index + 1) / number);
|
||||||
});
|
});
|
||||||
@@ -180,6 +183,18 @@ class ArtplayerToolThumbnail extends Emitter {
|
|||||||
throw new Error(msg);
|
throw new Error(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
destroy() {
|
||||||
|
this.option.fileInput.removeEventListener('change', this.inputChange);
|
||||||
|
document.body.removeChild(this.video);
|
||||||
|
if (this.videoUrl) {
|
||||||
|
URL.revokeObjectURL(this.videoUrl);
|
||||||
|
}
|
||||||
|
if (this.thumbnailUrl) {
|
||||||
|
URL.revokeObjectURL(this.thumbnailUrl);
|
||||||
|
}
|
||||||
|
this.emit('destroy');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
window.ArtplayerToolThumbnail = ArtplayerToolThumbnail;
|
window.ArtplayerToolThumbnail = ArtplayerToolThumbnail;
|
||||||
|
|||||||
Reference in new issue
Block a user