feat: add option to remove video source on destroy

- Introduced a new static property REMOVE_SRC_WHEN_DESTROY in Artplayer to control whether the video source should be removed when the player is destroyed.
- Updated the destroy method in Artplayer to conditionally remove the video source based on the new property.
- Removed the line that sets the video source to an empty string in the Template class's destroy method, as this is now handled in Artplayer.
- Updated TypeScript definitions to include the new REMOVE_SRC_WHEN_DESTROY property.
This commit is contained in:
Harvey Zack committed 2025-09-03 17:58:13 +08:00
1 parent cb3d391c34
commit 9bfd535e57
6 files changed
+9 -3

No files matched your search

+4
View File
@@ -203,6 +203,9 @@ export default class Artplayer extends Emitter {
}
destroy(removeHtml = true) {
if (Artplayer.REMOVE_SRC_WHEN_DESTROY) {
this.video.removeAttribute('src')
}
this.events.destroy()
this.template.destroy(removeHtml)
instances.splice(instances.indexOf(this), 1)
@@ -244,6 +247,7 @@ Artplayer.FLIP = ['normal', 'horizontal', 'vertical']
Artplayer.FULLSCREEN_WEB_IN_BODY = false
Artplayer.LOG_VERSION = true
Artplayer.USE_RAF = false
Artplayer.REMOVE_SRC_WHEN_DESTROY = true
if (utils.isBrowser) {
window.Artplayer = Artplayer
-1
View File
@@ -147,7 +147,6 @@ export default class Template {
}
destroy(removeHtml) {
this.$video.src = ''
if (removeHtml) {
this.$container.innerHTML = ''
}
+1
View File
@@ -86,6 +86,7 @@ export default class Artplayer extends Player {
static FULLSCREEN_WEB_IN_BODY: boolean
static LOG_VERSION: boolean
static USE_RAF: boolean
static REMOVE_SRC_WHEN_DESTROY: boolean
readonly id: number
readonly option: Option