fixed a bug on the web player

This commit is contained in:
2025-12-31 15:18:51 +01:00
parent 5e96a89a4b
commit d801a65602
2 changed files with 40 additions and 6 deletions

View File

@@ -410,11 +410,26 @@ const AnimePlayer = (function() {
} }
function initVideoPlayer(url, type, subtitles = []) { function initVideoPlayer(url, type, subtitles = []) {
const video = els.video; if (plyrInstance) {
Array.from(video.querySelectorAll('track')).forEach(t => t.remove()); plyrInstance.destroy();
plyrInstance = null;
}
if (hlsInstance) {
hlsInstance.destroy();
hlsInstance = null;
}
const newVideo = video.cloneNode(true); const container = document.querySelector('.video-frame');
video.parentNode.replaceChild(newVideo, video);
container.innerHTML = '';
const newVideo = document.createElement('video');
newVideo.id = 'player';
newVideo.controls = true;
newVideo.crossOrigin = 'anonymous';
newVideo.playsInline = true;
container.appendChild(newVideo);
els.video = newVideo; els.video = newVideo;
els.video.addEventListener("play", () => { els.video.addEventListener("play", () => {

View File

@@ -354,8 +354,27 @@ const AnimePlayer = (function() {
} }
function initVideoPlayer(url, type, subtitles = []) { function initVideoPlayer(url, type, subtitles = []) {
const video = els.video; if (plyrInstance) {
Array.from(video.querySelectorAll('track')).forEach(t => t.remove()); plyrInstance.destroy();
plyrInstance = null;
}
if (hlsInstance) {
hlsInstance.destroy();
hlsInstance = null;
}
const container = document.querySelector('.video-frame');
container.innerHTML = '';
const newVideo = document.createElement('video');
newVideo.id = 'player';
newVideo.controls = true;
newVideo.crossOrigin = 'anonymous';
newVideo.playsInline = true;
container.appendChild(newVideo);
els.video = newVideo;
if (Hls.isSupported() && (type === 'm3u8' || url.includes('.m3u8'))) { if (Hls.isSupported() && (type === 'm3u8' || url.includes('.m3u8'))) {
console.log("Using HLS.js"); console.log("Using HLS.js");