mirror of
https://github.com/MoonTechLab/LunaTV.git
synced 2026-05-20 04:47:30 +08:00
fix: try to fix airplay
This commit is contained in:
@@ -128,6 +128,28 @@ function PlayPageClient() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 在指定 video 元素内确保存在 <source src="...">,供部分浏览器兼容
|
||||||
|
const ensureVideoSource = (video: HTMLVideoElement | null, url: string) => {
|
||||||
|
if (!video || !url) return;
|
||||||
|
const sources = Array.from(video.getElementsByTagName('source'));
|
||||||
|
const existed = sources.some((s) => s.src === url);
|
||||||
|
if (!existed) {
|
||||||
|
// 移除旧的 source,保持唯一
|
||||||
|
sources.forEach((s) => s.remove());
|
||||||
|
const sourceEl = document.createElement('source');
|
||||||
|
sourceEl.src = url;
|
||||||
|
sourceEl.type = 'video/mp4'; // 默认类型,HLS 会被 Artplayer/Hls 处理
|
||||||
|
video.appendChild(sourceEl);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 始终允许远程播放(AirPlay / Cast)
|
||||||
|
video.disableRemotePlayback = false;
|
||||||
|
// 如果曾经有禁用属性,移除之
|
||||||
|
if (video.hasAttribute('disableRemotePlayback')) {
|
||||||
|
video.removeAttribute('disableRemotePlayback');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// 当集数索引变化时自动更新视频地址
|
// 当集数索引变化时自动更新视频地址
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
updateVideoUrl(detail, currentEpisodeIndex);
|
updateVideoUrl(detail, currentEpisodeIndex);
|
||||||
@@ -352,6 +374,10 @@ function PlayPageClient() {
|
|||||||
attachVideoEventListeners(
|
attachVideoEventListeners(
|
||||||
artPlayerRef.current.video as HTMLVideoElement
|
artPlayerRef.current.video as HTMLVideoElement
|
||||||
);
|
);
|
||||||
|
ensureVideoSource(
|
||||||
|
artPlayerRef.current.video as HTMLVideoElement,
|
||||||
|
videoUrl
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -544,6 +570,10 @@ function PlayPageClient() {
|
|||||||
attachVideoEventListeners(
|
attachVideoEventListeners(
|
||||||
artPlayerRef.current.video as HTMLVideoElement
|
artPlayerRef.current.video as HTMLVideoElement
|
||||||
);
|
);
|
||||||
|
ensureVideoSource(
|
||||||
|
artPlayerRef.current.video as HTMLVideoElement,
|
||||||
|
videoUrl
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('创建播放器失败:', err);
|
console.error('创建播放器失败:', err);
|
||||||
|
|||||||
Reference in New Issue
Block a user