fix(video): guard sourceless player play attempts

This commit is contained in:
2026-09-05 22:04:24 +08:00
parent 51dd38163d
commit 5a61e68a8c
2 changed files with 26 additions and 7 deletions
+12 -7
View File
@@ -153,7 +153,7 @@
self.hls.loadSource(self.src);
self.hls.attachMedia(self.video);
}
});
}).catch(function () { /* CDN unreachable: leave the player sourceless */ });
}
} else if (this.type === 'flv') {
loadScript(FLV_SRC).then(function () {
@@ -162,7 +162,7 @@
self.flvPlayer.attachMediaElement(self.video);
self.flvPlayer.load();
}
});
}).catch(function () { /* CDN unreachable: leave the player sourceless */ });
} else {
this.video.src = this.src;
}
@@ -172,9 +172,14 @@
}
};
AksrtVideoPlayer.prototype.hasSource = function () {
return Boolean(this.video.currentSrc || this.video.src || this.hls || this.flvPlayer);
};
AksrtVideoPlayer.prototype.toggle = function () {
if (!this.hasSource()) return;
if (this.video.paused) {
this.video.play();
this.video.play().catch(function () { /* source failed or autoplay blocked */ });
} else {
this.video.pause();
}
@@ -220,9 +225,9 @@
this.loadSource();
};
// ── 剧集切换按钮事件委托 ──
// ── 剧集切换按钮事件委托(iframe 剧集由 runtime main 的 .switch-iframe 链路处理)──
document.addEventListener('click', function (e) {
var switchBtn = e.target.closest('.switch-video, .switch-iframe');
var switchBtn = e.target.closest('.switch-video');
if (!switchBtn) return;
var container = switchBtn.closest('.aksrt-video') || switchBtn.closest('[data-aksrt-video]');
@@ -236,7 +241,7 @@
if (!container) return;
var src = switchBtn.dataset.src || switchBtn.getAttribute('video-url') || switchBtn.getAttribute('href');
if (!src) return;
if (!src || !/^https?:/i.test(src)) return;
e.preventDefault();
@@ -251,7 +256,7 @@
// 高亮当前集
var scope = switchBtn.closest('.featured-video-episode') || (container.parentElement || document);
var siblings = scope.querySelectorAll('.switch-video, .switch-iframe');
var siblings = scope.querySelectorAll('.switch-video');
siblings.forEach(function (btn) {
btn.classList.remove('is-active');
btn.classList.remove('active');