Skip to content

Commit

Permalink
fix: fix destroy api
Browse files Browse the repository at this point in the history
fix destroy is called,error will be triggerd
  • Loading branch information
yinguohui committed Aug 3, 2018
1 parent c27b5d9 commit bc3c4f2
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/xgplayer-hls/browser/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/xgplayer-hls/dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/xgplayer-mp4/browser/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/xgplayer-mp4/dist/index.js

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions packages/xgplayer-mp4/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,13 @@ let mp4player = function () {
}
})

player.once('destroy', () => {
Task.clear()
if (player.timer) {
clearTimeout(player.timer)
}
})

player._replay = function () {
Task.clear()
player.mp4.bufferCache.clear()
Expand Down
2 changes: 1 addition & 1 deletion packages/xgplayer/browser/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/xgplayer/dist/index.js

Large diffs are not rendered by default.

19 changes: 16 additions & 3 deletions packages/xgplayer/src/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,25 +111,38 @@ class Player extends Proxy {

destroy () {
let parentNode = this.root.parentNode
this.ev.forEach((item) => {
let evName = Object.keys(item)[0]
let evFunc = this[item[evName]]
if (evFunc) {
this.off(evName, evFunc)
}
});
['focus', 'blur'].forEach(item => {
this.off(item, this['on' + item.charAt(0).toUpperCase() + item.slice(1)])
})
if (!this.paused) {
this.pause()
this.once('pause', () => {
this.emit('destroy')
parentNode.removeChild(this.root)
parentNode.appendChild(this.rootBackup)
for (let k in this) {
if (k !== 'config') {
delete this[k]
}
}
})
} else {
this.emit('destroy')
parentNode.removeChild(this.root)
parentNode.appendChild(this.rootBackup)
}
setTimeout(function () {
for (let k in this) {
if (k !== 'config') {
delete this[k]
}
}
}, 200)
}
}

replay () {
Expand Down

0 comments on commit bc3c4f2

Please sign in to comment.