Skip to content

Commit

Permalink
fix video (#814)
Browse files Browse the repository at this point in the history
  • Loading branch information
xpy01xpy authored Oct 14, 2024
1 parent 9957630 commit fab4219
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/components/home/HomeCardPlayer.astro
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ const t = useTranslations(Astro);

<script>
class HomeCardPlayer extends HTMLElement {
currentId: any;
flagState: any;
cardSolution: any;
videoPlayButtons: any;
constructor() {
super();
// 初始化时不要访问 DOM 或设置属性
Expand Down Expand Up @@ -187,7 +191,11 @@ const t = useTranslations(Astro);
if (video.paused) {
// 在播放当前视频前,先暂停其他所有视频
this.pauseOtherVideos(videoId);
video.play();
video.play().catch(error => {
// 播放时发生错误: AbortError: The play() request was interrupted by a new load request.
// 第一次播放失败时,可以尝试重新加载视频;
video.play();
});
this.onPlay(e);
} else {
video.pause();
Expand Down Expand Up @@ -254,8 +262,7 @@ const t = useTranslations(Astro);


<script>
// Lazy loading using IntersectionObserver
document.addEventListener('DOMContentLoaded', () => {
const bindEvent = () => {
const lazyVideos = document.querySelectorAll('.lazy-video');

if ('IntersectionObserver' in window) {
Expand Down Expand Up @@ -284,8 +291,10 @@ const t = useTranslations(Astro);
video.load(); // Optionally, start loading the video
});
}
});

}
// Lazy loading using IntersectionObserver
document.addEventListener('DOMContentLoaded', bindEvent);
document.addEventListener("astro:after-swap", bindEvent);
</script>

<style is:global>
Expand Down

0 comments on commit fab4219

Please sign in to comment.