This commit is contained in:
yumoqing 2025-09-10 16:56:03 +08:00
parent 508b127e75
commit e3fa9e7028

View File

@ -62,6 +62,17 @@ bricks.VideoPlayer = class extends bricks.VBox {
this.bind('domoff', this.destroy.bind(this)); this.bind('domoff', this.destroy.bind(this));
} }
destroy(){
if (this.hls) {
this.hls.destroy();
this.hls = null;
}
if (this.dashPlayer) {
this.dashPlayer.reset();
this.dashPlayer = null;
}
this.video.src = ''; // 清空
}
init() { init() {
this.loadVideo(this.opts.url); // 可替换为 mp4 / m3u8 / mpd this.loadVideo(this.opts.url); // 可替换为 mp4 / m3u8 / mpd
this.bindEvents(); this.bindEvents();
@ -73,16 +84,7 @@ bricks.VideoPlayer = class extends bricks.VBox {
loadVideo(src) { loadVideo(src) {
// 销毁旧播放器 // 销毁旧播放器
if (this.hls) { this.destroy()
this.hls.destroy();
this.hls = null;
}
if (this.dashPlayer) {
this.dashPlayer.reset();
this.dashPlayer = null;
}
this.video.src = ''; // 清空
if (src.endsWith('.m3u8') || src.includes('m3u8')) { if (src.endsWith('.m3u8') || src.includes('m3u8')) {
if (Hls.isSupported()) { if (Hls.isSupported()) {